Next.js Discord

Discord Forum

SSG and private routes

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
Hi guys, what do you think how I can achieve this. I want to have SSG for application which is private. But when I have a page wrapper with condition (if user is logged then render him a page, except that render him a loading spinner), but in that case I always render all pages with loading spinner (becase we don't have a logged user on the server). And when I set processing isLogged value only on client side, than I have a flash of private content until user get javascript file
Answered by American black bear
For next generation, may help 🙂
I did this successfuly with Next.js Middleware. I set user token (in login function) in the cookie and pull that cookie in the middleware. Validate user token, and based on that redirect on /login page or not
View full answer

2 Replies

American black bearOP
For next generation, may help 🙂
I did this successfuly with Next.js Middleware. I set user token (in login function) in the cookie and pull that cookie in the middleware. Validate user token, and based on that redirect on /login page or not
Answer