Session sometimes disappear
Answered
European hornet posted this in #help-forum
European hornetOP
Im using Nextjs(12.3.0) and NextAuth(4.10.3)
I got a question about session.
In my cart page(local and production), it is weird that session sometimes disappear when user enter input or upload photos, especially in mobile devices.
Could somebody help me about this bug?
I got a question about session.
In my cart page(local and production), it is weird that session sometimes disappear when user enter input or upload photos, especially in mobile devices.
Could somebody help me about this bug?
Answered by European hornet
@riský mate, I sloved the problem! I replaced useSession with getSession and modify some logic of my code.
27 Replies
how are you storing the cart? localstorage? or in the session token?
European hornetOP
I am actually storing the cart in database, when adding or removing a item, I call an API and store them in DB
@European hornet I am actually storing the cart in database, when adding or removing a item, I call an API and store them in DB
European hornetOP
Each user per record, btw
can you show your code and possibly an example as im not sure i understand whats happening...
@riský can you show your code and possibly an example as im not sure i understand whats happening...
European hornetOP
sure, I’ll post my code once I come back home!
European hornetOP
@riský update, the case I mentioned only happen on android phones
and not desktop browser?
so some weird state issue i see...
does the page reload or something when they are doing said actions
@riský does the page reload or something when they are doing said actions
European hornetOP
the page does not reload
European hornetOP
@riský the api/auth/session fail after I upload file from mobile device
sorry, i fogot all about this 

European hornetOP
no worries

but i think it could be either a libary haveing weird state or your phone pausing the tab and reopening it, but weird state (fror batter perf)
European hornetOP
BTW, my nextjs version is 12.10.3 and NextAuth version is 4.10.3
ohh we are up to next 13 now
@riský but i think it could be either a libary haveing weird state or your phone pausing the tab and reopening it, but weird state (fror batter perf)
European hornetOP
I think when I open my mobile device file system, the state become weird
if you open the page and close browser and re-open it a few secs later, does the same thing occur
@riský ohh we are up to next 13 now
European hornetOP
I cannot update any of them since it is in production
@riský if you open the page and close browser and re-open it a few secs later, does the same thing occur
European hornetOP
no it won't happen, session is kept.
@European hornet I cannot update any of them since it is in production
well, this kinda makes it hard for me to help as i have only doe nextjs 13 mostly with app dir...
and lots of things have prob changed
European hornetOP
no worries, I'm really appreciated your help!
and i see you have done everything you can do... it may not be possible for you to solve simply if nextjs 12 has a bug like that
but the cart page doesn't use nextauth much (only for checking who the user is)?
@riský and i see you have done everything you can do... it may not be possible for you to solve simply if nextjs 12 has a bug like that
European hornetOP
and need to send the user info provided by the session to the API route >>>> the cart would stuck at this point
European hornetOP
@riský mate, I sloved the problem! I replaced useSession with getSession and modify some logic of my code.
Answer