supabase: Auth middleware example from docs does not work
Version
@nuxtjs/supabase: 0.3.0 nuxt: 3.0.0
Steps to reproduce
Create an auth.ts file in the middleware folder as described here: https://supabase.nuxtjs.org/usage/composables/use-supabase-user#auth-middleware
What is Expected?
For a user to be redirected to the correct page after logging in.
What is actually happening?
When a user logs in, no redirect happens because the user object doesn’t exist when using theuseSupabaseUser() in the auth.ts file. This means the check is is always false and the user is redirect to the /login page.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 16
- Comments: 22
The demo has been updated with the last version of both Nuxt and Supabase Module. It’s deployed on Netlify. It’s using middleware as it is explained in the doc. Please let me know if you are still experiencing this issue on your own project. A reproduction is needed to help 🙏
I did also notice that, even when using that composable, the middleware still did not receive the data of the user until those cookies were created. And that still required a tab-out and tab-in to accomplish. I managed to get it to work by altering the middleware to this:
It may not be optimal, but it works.
Same here, I’m using the useSupabaseAuthClient to login and logout, and it works locally. But on Netlify it doesn’t.
I fixed it by using
useSupabaseAuthClient()instead ofuseSupabaseClient()to sign in and out.I am also experiencing this issue. It does not occur when testing locally, only when hosted on Vercel.
Strangly enough this does not solve the issue for me locally. I tried creating a minimal example but you can’t really do this without running Supabase itself, otherwise there is nothing to login to.
My setup is really simple and I fail to see what it incorrect. My login component looks like:
And the middleware file is exactly the same as in the official example in the docs:
I don’t think we should close this issue just yet. Any ideas what this could be?
Thanks!