Skip to content

A way to check the auth token refresh state #335

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

Closed
xylish7 opened this issue Jul 29, 2022 · 3 comments
Closed

A way to check the auth token refresh state #335

xylish7 opened this issue Jul 29, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@xylish7
Copy link

xylish7 commented Jul 29, 2022

Feature request

Is your feature request related to a problem? Please describe.

If the auth token expires and the user navigates to the web app, then for half a second the public routes are shown (while the auth token is refreshed) and then the private routes are being shown.

The problem is that there is no way to track when a new token is fetches, so that I can show, for example, a loader.

This leads to bad UX and the users thinks they are logged out, but after half a second they are logged in again.

I know you can check the supabase.auth.session() to see if the users is logged in but this won't help as you only get null or a value and it is not actually a promise on which you can wait.

Describe the solution you'd like

Maybe emit an event in onAuthStateChange, like REFRESHING_TOKEN so the UI can show something relevant.

@xylish7 xylish7 added the enhancement New feature or request label Jul 29, 2022
@pixtron
Copy link
Contributor

pixtron commented Jul 29, 2022

#285 introduces async getSession() and async getUser(). This PR has been merged and published to npm @next.

const initializeSupabase = async () => {
 	const supabase = createClient(...);
	
	const { error, session } = await supabase.auth.getSession();

	// if session === null at this point you can be sure the 
	// user is not logged in otherwise the user is logged in
}

If you like to beta test gotrue-js @next you can use it like this:

  1. add "@supabase/gotrue-js": "next", to dependencies in package.json
  2. add a new overrides node to the root of your package.json
"overrides": {
    "@supabase/supabase-js": {
      "@supabase/gotrue-js": "$@supabase/gotrue-js"
    }
  }
  1. npm install

Eventually you have to remove the node_modules folder and packge-lock.json and then reinstall.

@xylish7
Copy link
Author

xylish7 commented Jul 29, 2022

Will give it a try! Thank you for your fast response! 😊

@xylish7
Copy link
Author

xylish7 commented Jul 30, 2022

It seems like it works ok for my case. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants