You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem with this approach when you refresh the page the page renders for few milliseconds then the redirect happen because The redirect check is on useEffect. How to prevent page from rendering before checking?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple Protected Route for my pages that checks for authentication only on Client-side
The problem with this approach when you refresh the page the page renders for few milliseconds then the redirect happen because The redirect check is on
useEffect
. How to prevent page from rendering before checking?If I try to remove the
useEffect
:I'll get
Error: No router instance found.
error, How to prevent this page from rendering on server?Another suggestion I've got to do this:
I'll get
Invalid hook call, Hooks can only be called inside of the body of a function component
because ofuseRouter
.Why it is so hard to make protected route with Next.js?
Beta Was this translation helpful? Give feedback.
All reactions