Next.js Discord

Discord Forum

Simplest way to protect an admin dashboard route?

Unanswered
Siamese posted this in #help-forum
Open in Discord
SiameseOP
2 users for my app:
- admin: updates info
- viewer: anon, view info

7 Replies

Auth.js + Prisma. add role field: admin and viewer to User table. check a session to identify admin/viewer in APIs and Routers. it take a few days to get it all done.
before get to that, study the diff btw authentication and authorization in general.
SiameseOP
can i do it without a database? i will only store 1 user after all
yes. you can hard code the logic and Auth.js allows you to use a JWT without DB
hard-code an autherization logic like
if email == 'cashew@gmail.com` {
    user.role = 'admin'
SiameseOP
alright thanks!
u can see my POC project here, which does not use DB. mail prover is hard-coded.
https://github.com/tfutada/zenn-nextjs/blob/d65d96e3e50df5cfeade519a6e4c5fa4f8ad8e9a/app/options.ts#L38