-
Notifications
You must be signed in to change notification settings - Fork 125
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
useSupabaseUser() is not updated until I leave the browser window or switch browser tabs #144
Comments
I am having this same issue. Why was this closed? |
I've tried both npm run dev and Netlify Dev locally and neither works. I've tried Chrome, Safari, and Firefox. The auth tokens cookies are also set properly. |
signInWithOAuth method is not returning any session data. If you want to work around with using signInWithOAuth and Nuxt 3, here is my solution. It works like a charm (even on mobile browsers like Safari, Chrome). anyone can use this solution until fix is realeased.
|
@bayramorhan hi! It might not be the same issue. I get session data from the client and cookies are set. It's just the useSupabaseUser() that is not updated accordingly. |
hi @anderslutzhoft . I also experienced your exact problem. After oAuth is complete and redirected, nothing changes, there is no session data. But as soon as I switch between tabs, the data was there. So, populating session data with useCookie() fixed my problem. Im just curious about what is different on your code and why this workaround is not solving your problem. maybe you can share some code. |
Hi, i've been struggling with this issue for a while now. The session cookies are only set after i switch the tab etc.. and this is what i cameup with using getSession and refreshSession using supabase client as in the docs. Dont know if this is the right way but works for now(NB: only in non SRR mode) export default defineNuxtRouteMiddleware(async(to, _from) => {
const supabase = useSupabaseClient()
let {data}= await supabase.auth.getSession()
if(!data.session){
const { data, error } = await supabase.auth.refreshSession()
let {user} = data
if(!user){
return navigateTo('/login')
}
}else{
if(!data.session.user){
return navigateTo('/login')
}
}
}) I havent really tested out if the refreshSession is actually required, and i think not, but i just put it there as a failsafe |
Im using with ssr mode and setting cookies manually is mandatory thing until they fix this |
Hi @bayramorhan it seems like the onAuthStateChange() is not firing until I switch tabs, so unfortunately, it doesn't fix my issue :( Are you running SSR? |
I found a fix that worked for me. the values of access and refresh tokens where respectively the same.
all of this done in the login_handler method. |
Any news on that topic? |
I have managed to fix it with the solution above BUT and its a big but, it seems sometimes this solution is also not working. |
I got it working on localhost, but after deploying it to vercel it's back to tab-switching for it to work... Edit: Even locally it's only working sometimes. |
so this might sound weird, but have you guys tried using |
The way I got it working again was to manually update the gotrue-js package to the latest version. |
Using useSupabaseAuthClient resolved signOut issue but its not resolved session problem. |
I realized that this module is not even at a major release. It's 0.5.0. So I reverted back to using the native SupabaseJS, and it works as it should. |
Can you share on how you did it? Thought about switching to native aswell. |
Firstly I configured the whole app to CSR instead of SSR just to be sure. And then I just followed the instructions in the documentation and examples. |
Dude, this made it for me. Changed it and login with password worked flawlessly. Unfortunately documentation is lacking. |
I have a reproducible case of this - using See if my repo exhibits the problem you're all seeing? When I login (using |
It seems to me that the issue stems from the gotrue package. Once it's updated to the latest version, everything is working as intended. |
I am using the latest gotrue-js package - v2.11.0 - there is nothing later that I can see, and it is still exhibiting the bug. |
I have this issue as well. And this issue has been open for a month with no admin attention. @larbish can you please take a look? |
I'm using the useSupabaseAuthClient composable and still observing the same behavior, nothing updates until the window loses focus |
I'm sorry guys but since I'm working hard on the beta opening of the Nuxt Studio and because I'm only using the supabase module for side projects that are all working well on production, I don't have much time to check issues if reproduction is missing. The demo is working as expected and deployed on Netlify. Please check it and if you can easily reproduce your wrong behaviour, create and share a repository to reproduce, I'll find a moment to help 🙏 |
Hey @larbish, thanks for taking the time to address this ❤️ I believe this could be a reproduction of the issue:
Current behavior:
https://stackblitz.com/edit/nuxt-starter-tefz9j?file=pages/login.vue
EDIT: Something is happening that shouldn't: a |
Hey @MAXOUXAX, thanks for the reproduction. The user returned by the
I will update the documentation to explain it. NB: Concerning the |
I'll apologize in advance if this is a beginner's question, but I've tried searching for an answer, and I can't seem to find any addressing the issue I have.
I use this module and I can successfully login using email and password, but for some reason, the user session is not updated within useSupabaseUser() until I leave the browser window or switch tabs and come back. Even if I refresh the page the useSupabaseUser() is not up to date. I have tried watchers, plugins, etc., but to no avail.
But as soon as I leave the browser window for a second, everything is updated and working as expected.
I would be really grateful if anyone could point me in the right direction!
The text was updated successfully, but these errors were encountered: