Now, you are learning the implement authentication with JWT in next js about user Role which is having as editor, users and admin. It is very important for Auth. But you can login with google too. here, we are share about Next js Prisma, jsonwebtoken for jwt , and any other requests Packages for it.

npm install next prisma jsonwebtokent

But, Right now, there is no need to install npm Package. next js auth has ready for it. the firstly, you are going to Set up Prisma, it is run “npx prisma init”, o initialize with Prisma, and then define your models in the schema.prisamĀ file.

  1. Create JWT functions.

Create the file as functions for generating JWT tokens, verifying them, and extracting user information

2.Authentication Middleware:

You can create a middleware to handle authentication. This middleware can be used in your API routes or wherever authentication is needed.

3. User Prisma in API router but there has the router function now, it is App router and page Router thus what you are going to use you can create with it. Implement logic in your routes to differentiate between admin and user roles and perform actions accordingly.

Thank you so much.