bit of a doozy here; i'm trying to use an iframe t...
# help
a
bit of a doozy here; i'm trying to use an iframe to have universal auth on all related sites to my project (so not every site associated has to have its own login page, just uses the auth server), and supabase cant seem to get the session from localstorage through the iframe, however if i go to the page in my browser normally, it works just fine. is this something with supabase/gotrue or javascript (or my code)? thanks!
n
Hello @AmusedGrape! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
a
iframe code:
Copy code
js
export default function OneSignIn() {
  const { user, loading, login, logout, session } = useAuth();

  console.log(user, loading, session);

  return (
    <div>
      <script
        id="sendToParent"
        dangerouslySetInnerHTML={{
          __html: `
            window.parent.postMessage({
              type: 'authenticate',
              payload: {
                authed: ${user ? true : false},
                session: '${supabase.auth.session()}',
              },
            }, "*")
        `,
        }}
      />
    </div>
  );
}
page code:
Copy code
js
  useMessage('authenticate', (send, payload, origin) => {
    console.log(payload); // returns session as null
    if (payload.authed) {
      setIsAuthenticated(true);
      const session = supabase.auth.setAuth(payload.session);
      setSession(session);
      setUser(supabase.auth.user());
      setLoading(false);
    } else {
      setIsAuthenticated(false);
      setSession(null);
      setUser(null);
      setLoading(false);
      if (authGuardedPages.includes(router.pathname)) {
        // router.push(
        //   `${process.env['NEXT_PUBLIC_ONEAUTH_ENDPOINT']}/?redirect=${origin}${router.pathname}`
        // );
      }
    }
  });
n
Thread was archived by @AmusedGrape. Anyone can send a message to unarchive it.
AmusedGrape (2022-03-12)