Back

Implementing User-Role Based Protected Routes (Pages) using Next.js & AppWrite: Seeking Guidance

  • 0
  • Self Hosted
  • Web
Badeck
12 Jan, 2024, 23:29

Hello everyone,

I'm new to Next.js, so please bear with me as I'm still in the process of familiarizing myself with the documentation.

I'm looking to create a web app where I can secure specific routes (pages) based on user roles.

Consider this straightforward use case:

  • If a user is not logged in, they should only be able to access the landing page.
  • Once logged in, a user gains access to a dashboard.
  • For users with the role "Moderator" in addition to being logged in, they should be able to access the same dashboard plus an additional protected page that regular users cannot access.

I'd appreciate any guidance or examples on how to implement this within the Next.js framework.

Thank you in advance!

TL;DR
The developer is new to Next.js and wants to create a web app with user-role based protected routes. They want to restrict access to certain pages based on user roles. They are looking for guidance on how to implement this in Next.js. Solution: One suggestion is to use JSON Web Tokens (JWT) for authentication and middleware for route protection. Another suggestion is to refer to a project on the AppWrite website for more information.
Badeck
12 Jan, 2024, 23:32

I gathered some ideas on google mentionning Json Web Tokens, middleware or even this https://builtwith.appwrite.io/projects/645ce5e378593e15fcd1/

D5
12 Jan, 2024, 23:58

I recommend following that way. It's possible with JWT too but that's more recommended and is probably more straightforward than relying on JWT

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more