Next.js Discord

Discord Forum

NextJs and NodeJs combination, how to protect route?

Answered
Wool sower gall maker posted this in #help-forum
Open in Discord
Wool sower gall makerOP
I wanna protect route on nextjs so that only admin user can access it , what's best approach to do that? I was thinking just fetching the user and check it's role, but then the regular user still sees the route exists? what would be better thing to do?
Answered by B33fb0n3
you can do that inside your middleware. Check the permissions inside your middleware and either redirect the user to the notFound page or redirect him to the correct page 👍
View full answer

5 Replies

@Wool sower gall maker I wanna protect route on nextjs so that only admin user can access it , what's best approach to do that? I was thinking just fetching the user and check it's role, but then the regular user still sees the route exists? what would be better thing to do?
you can do that inside your middleware. Check the permissions inside your middleware and either redirect the user to the notFound page or redirect him to the correct page 👍
Answer
@Wool sower gall maker solved?
@B33fb0n3 <@285022897146167307> solved?
Wool sower gall makerOP
yes, thanks
happy to help 🙂