-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
feat: use access token from ram instead of from auth.getSession()
#15933
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
48d7ede
to
46c1e67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just one question:
auth.onAuthStateChange((event, session) => { | ||
currentSession = session | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this 100% safe to call on the server? Could always do something like:
auth.onAuthStateChange((event, session) => { | |
currentSession = session | |
}) | |
if (typeof window !== 'undefined') { | |
auth.onAuthStateChange((event, session) => { | |
currentSession = session | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, it just registers a callback.
#getSession()
in gotrue-js can be a bit slow as it has to read fromlocalStorage
all the time to make sure it's returning consistent data. With some changes that are coming (see #15795) it's going to be even slower as there would only be a single such call per tab.By storing and using the access token as seein in
onAuthStateChanged
notifications, issues of slowness or concurrent access will be significantly reduced. This is absolutely safe, as any tab that changes the session broadcasts the changes to other tabs. This might significantly reduce the reported occurrence of random logouts when using the SQL editor.