user15678236
user15678236

Reputation:

Access localStorage before page rendering in nextjs

I want user will not redirect to login page on closing website or browser once user is loggedIn.for this i use localStorage. it is working successfully but, it works after page rendering in nextjs. so, it give me error for 5 seconds. i want to access localStorage before page rendering in nextjs.[![First image shown when website is launchThen the routes automatically changes after 5 secondsThis is my code for accessing localStorage and setting conditions

Upvotes: 0

Views: 716

Answers (1)

Shea Hunter Belsky
Shea Hunter Belsky

Reputation: 3218

Local Storage is only available in the browser. It will not be available on the server (or while the page is doing any kind of server-side operation).

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

You should use a cookie to store this information if it needs to be accessible by both the server AND client.

Upvotes: 2

Related Questions