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: add async getters for session and user. #265

Closed
wants to merge 1 commit into from
Closed

feat: add async getters for session and user. #265

wants to merge 1 commit into from

Conversation

lebrinkma
Copy link

What kind of change does this PR introduce?

adds async getters for session and user.

this provides a workaround for #143 and #23 without needing setTimeout.
this is an alternate solution to #147.

What is the current behavior?

After const supabase = createClient(supabaseUrl, supabaseKey)
supabase.auth.session() and supabase.auth.user() might return null,
if the session is expired and currently refreshing or if the session is recovering from a magic link.

What is the new behavior?

refreshedSession() resp. refreshedUser() wait for the pending recovery and
and return valid session resp. user data.

usage examples

const session = await supabase.auth.refreshedSession()
const user = await supabase.auth.refreshedUser()

Additional context

for supabase-js v2 (supabase/supabase-js#170)
user() and session() should IMHO be async functions.

usage examples `const session = await supabase.auth.refreshedSession()` and
`const user = await supabase.auth.refreshedUser()`.

this provides a workaround for #143 and #23 without needing setTimeout.
this is an alternate solution to #147.
@alaister
Copy link
Member

alaister commented Jun 1, 2022

Hey @lebrinkma,

Thanks for this - sorry I didn't see it sooner!

This is now being tracked in #285. Any comments you have are welcome there :)

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