LocalStorage has been auto removed in Safari (Next.js project)

I am building a Next.js project which has an authentication process.
First, a user enter email and password then he will get a jwt token
I try to set the jwt token to the localStorage and access this value to call other authenticated APIs.
Google Chrome is working fine.
Only Safari is cleared my localStorage by itself and API calls failed.

You need to enable it in the browser settings; if you’re blocking cookies, Safari treats local storage as the same thing. Note there’s exactly the same issue (if you can call it an issue), on IOS, regardless of browser – technically IOS only has Safari, all other browsers are just skins over the WebKit engine that Safari runs on

My settings is already allows.
Another thing is, it not possible to deal with each end user. So, what will be the identical solution for this kind of scenario.

Without more information, the overwhelmingly likely reason, given that this only occurs in Safari, is that there is something in your Safari that is blocking cookies, on your machine (and, by extension, for Safari, that also means local storage).

Local storage definitely isn’t broken for Safari, and there are aren’t any special tricks required to make sure it works in that browser, so this is why I’m saying it’s overwhelmingly likely.

There may be another reason, but without any context it’s impossible to tell.

There isn’t a solution, it’s entirely up to an individual user whether they block localStorage or not; 99% of them won’t, but you can’t force that other 1% to do what you want. It’s not an issue – it’s not up to you whether someone wants to save things on their machine.

1 Like

thanks for the comments! I understood

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.