Admin dashboard
How could I create an admin dashboard where if the user is not authenticated with next-auth it goes to /login but if he does not have admin give a 403 ? Maybe something like roles ?
Solution:Jump to solution
There is a guide that might help: https://authjs.dev/guides/basics/role-based-access-control
Role-based access control | Auth.js
There are two ways to add role-based access control (RBAC) to your application, based on the session strategy you choose. Let's see an example for each of these.
3 Replies
Definitely roles do need to be involved.
Once you set them up, you can use getServerSideProps to redirect ( return {redirect: ... } ) or throw 403.
Is there anything in next-auth that does the role easily ?
Solution
There is a guide that might help: https://authjs.dev/guides/basics/role-based-access-control
Role-based access control | Auth.js
There are two ways to add role-based access control (RBAC) to your application, based on the session strategy you choose. Let's see an example for each of these.