Comments (6)
With this change, the event never fires and thus the page does not get updated for logged in users
because session recovering now happens on constructor which is before any onAuthStateChange subscription.
For your use case, You can check for current session along with onAuthStateChange
supabase.auth.onAuthStateChange((event, session) => {
// on event == SIGNED_IN, do s.th
})
if (supabase.auth.session()) {
// user login, do s.th
}
from gotrue-js.
Here's the workaround function I have made for now:
type AuthChangeHandler = (event: supabase.AuthChangeEvent, session: supabase.Session | null) => void;
export function onAuthStateChange(client: supabase.SupabaseClient, callback: AuthChangeHandler) {
document.addEventListener('DOMContentLoaded', function() {
if (client.auth.session()) {
callback('SIGNED_IN', client.auth.session());
}
});
client.auth.onAuthStateChange((event, session) => {
callback(event, session);
});
}
from gotrue-js.
One year later is this workaround still necessary?
I'm trying to use Supabase again after about a year of absence and I found that following the examples given by the docs sometimes the events don't get fired especially when trying to use a third-party OAuth provider like GitHub.
The user is redirected back to my sign in page with an access token in the URL but then nothing happens.
I expect the event to be fired and the user to get redirected to the dashboard on server side, but that's not the case.
from gotrue-js.
Hey @ProjectMoon - you're right - we had to re-eng this so that it would return from the constructor instead.
The problem is very apparent in a multi-page application/"regular website" with a Supabase connection
Can you clarify more about the problem? Not you should be able to inspect supabase.auth.session()
immediately (like this), and this will return a logged-in session (if there is a valid session)
from gotrue-js.
The session exists and the user is logged in, yes. I have a very simple website where a user can log in to get a bit more information. Originally on Firebase, and before the recent changes, I relied on the auth state change event to fire so I could fetch and display the information/links/etc for logged in users. With this change, the event never fires and thus the page does not get updated for logged in users.
Is there a workaround maybe?
from gotrue-js.
Hi @milovangudelj, it would be great if you can elaborate more on this point:
I expect the event to be fired and the user to get redirected to the dashboard on server side
The event only gets fire after the user is redirected to the dashboard. This is because we can only confirm that the user is signed in if the oauth callback is successful.
If the oauth callback is successful and the user is redirected to the dashboard, there should be a "SIGNED_IN" event fired which you can listen to using onAuthStateChange
. Will be closing this issue for now but feel free to reopen if you wish to clarify and elaborate on your usecase.
from gotrue-js.
Related Issues (20)
- `GoTrueClient` Memory Leak HOT 24
- No recovery email sent after sign up a second time after provider login HOT 1
- Error: Permission denied to access property "then" for Firefox Extensions HOT 1
- supabase.auth.signInWithIdToken() authunknownerror when used on real ios device
- Add missing 'is_anonymous' property to the User type
- Can't get rid of getUser() warning HOT 121
- "User with this email not found" error when using generateLink HOT 9
- Google OAuth doesn't work in Safari with next-js-auth-helpers HOT 1
- New, unsigned in user can not be deleted from supabase console. HOT 1
- [email protected] breaks client auth with edge functions HOT 15
- New error code is missing in error object
- user object warning logged, even when not touching `session.user` HOT 34
- Security and performance risk with `getUser` and `getSession` HOT 6
- Global supabase.auth.signOut() doesn't fire the "SIGNED_OUT" event for onAuthStateChange in other instances where a user is logged in HOT 5
- Current session lost when auth function call fails HOT 1
- Impossible to check null session without getSession warning HOT 9
- `getSession` should validate the session with the JWT_SECRET HOT 2
- getAuthenticatorAssuranceLevel() triggers "getSession() could be insecure" warnings HOT 3
- PKCE flow issue with other than supabase `code` query in URL
- Still having getSession warning whenever _saveSession is called HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gotrue-js.