[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

feat: use access token from ram instead of from auth.getSession() #15933

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

hf
Copy link
Contributor
@hf hf commented Jul 20, 2023

#getSession() in gotrue-js can be a bit slow as it has to read from localStorage 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.

@hf hf requested a review from a team as a code owner July 20, 2023 17:51
@vercel
Copy link
vercel bot commented Jul 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
studio-self-hosted ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
supabase-studio-prod ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
supabase-studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm
zone-www-dot-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 6:18pm

Copy link
Member
@alaister alaister left a 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:

Comment on lines +92 to +94
auth.onAuthStateChange((event, session) => {
currentSession = session
})
Copy link
Member

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:

Suggested change
auth.onAuthStateChange((event, session) => {
currentSession = session
})
if (typeof window !== 'undefined') {
auth.onAuthStateChange((event, session) => {
currentSession = session
})
}

Copy link
Contributor Author

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.

@hf hf merged commit 50f7c1c into master Jul 28, 2023
@hf hf deleted the hf/use-access-token-from-ram branch July 28, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants