Is there any way to implement remember me and login using localstorage through api in Nextjs and Laravel?

I currently working on a MIS using nextjs for frontend ,Laravel for backend and laravel passport for authentication. I have problem implementing remember me and login with api. I want a to write a code that if a user does’nt check remember me while logging in the info of the user is deleted when browser is closed or tab is closed but when the user checks the remember me the credintials remain in the browser and every time he comes the credintials are validated by the server to check if the info is valid.

  1. I tried to store the user with not remember me in state using redux and the remember me one in localstorage but it logs me out when the page is refreshed.

  2. I tried using session storage, it deletes when the browser or tab is closed, it stays when page is refreshed but the problem with that is when opening a new tab the session is not shared between tabs and every tab needs to login again.

  3. I could use a flag in localstorage whether the user selected remember or not and when it is true the user is automatically logged in but I am not happy with storing anything unless the user selects remember me.

I run out of options, If there is any other way that I am not aware of I would appreciate if you share with me.
If nothing I think I would stick with option number 3.

Source: Laravel

Leave a Reply