Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fire signed in event on recoverSession. #30

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

thorwebdev
Copy link
Contributor

What kind of change does this PR introduce?

Fixes #23

For environments where localstorage is async (e.g. AsyncStorage on React Native), fire a SIGNED_IN onAuthStateChange event as soon as the session has been recovered from localStorage.

That way the following pattern should solve things across the board: https://github.com/thorwebdev/nextjs-subscription-payments/blob/main/components/UserContext.js#L13-L28

useEffect(() => {
    const session = supabase.auth.session();
    setSession(session);
    setUser(session?.user ?? null);
    const { data: authListener } = supabase.auth.onAuthStateChange(
      async (event, session) => {
        setSession(session);
        setUser(session?.user ?? null);
      }
    );

    return () => {
      authListener.unsubscribe();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

@kiwicopple kiwicopple merged commit 0e7473c into master Dec 11, 2020
@kiwicopple kiwicopple deleted the fix/recoverSession-fire-event branch December 11, 2020 07:03
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

session() and user() reportedly not returning data on first invocation
2 participants