-
-
Notifications
You must be signed in to change notification settings - Fork 196
onAuthStateChange when using signup email link in React #615
Description
Bug report
Describe the bug
When signing up using email, the user successfully gets redirected to the redirectTo link specified with the correct access and refresh tokens. They get picked up by supabase and the session gets saved to the localstorage.
However no onAuthStateChange
event is fired, only after refreshing the page the session gets parsed from the local storage and the event is fired.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Add event listener to app.js:
useEffect(() => { supabase.auth.onAuthStateChange((_event, session) => { console.log("Got session form onAuthStateChange", session, _event); }); }, []);
2.. Call supabase.auth.signup to generate the email
supabase.auth.signUp({ email, password }, { redirectTo: "{our_url}/login"})
- Click on the email link
- User get's redirected to our /login#access_token:ey... which is correct
- Token get's parsed and localstorage get's updated successfully with the new session.
- However: No onAuthStateChange() event is fired, only after refreshing the page the event get's fired.
Expected behavior
Once supabase obtains a valid session and updates it in the localstorage, the onAuthStateChange should get fired.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: Windows
- Browser Chrome / Firefox (others not tested)
- Version of supabase-js: ^1.33.3
- Version of Node.js: 17.0.2
Additional context
We're trying to redirect the user back to the login screen after successful signup as we have a hook that checks if a session already exists and redirect users either to the appropriate homepage (profile signup, dashboard, ...).
However this functionality isn't working as no session is set after accessing the page from the email signup link.