Iframe doesn't immediately recognise authenticated user

I have two pages that share the same users database and both pages have “remember user” functionality enabled and the second page is nested within the first page as an iframe element.

However, when you login to parent page after the remembering time has expired, the child page still asks for a login. If you then reload, both parent and child pages don’t require authentication(since your login is remembered).

Seems to me that there’s possibly a slight lag between you logging in to the parent and the child realising you’ve been logged in.

Could someone offer some input if this is plausible and how to fix it?

Thanks

iframes are tricky, since they don’t share a session with the parent page. That’s why the login isn’t recognized between them. After you login to both, they both remember their individual logins.

I gave up on iframes for this very reason. I know some others here still use them, so hopefully you’ll get some decent workarounds.

As a non-iframe workaround if the iframe is in one Anvil app and is embedding another Anvil app you could have the second Anvil app be a dependency and just use its forms directly. Then the login status would automatically be shared.

I think if you reload the iframe in code after a successful login it should refresh. And it seems u can do that by resetting the src attribute like this: iframe.src = iframe.src; (haven’t tested, just asked GPT how to refresh an iframe).