Reputation: 31
I am new in Next.js and it turorials recommend using NextAuth.js for authentication and authorization.
My current app will use .Net 8 Web API as backend and have supported authentication and authorization to protect routes. It will return a JWT token and other necessary data back to client after users logged in. Every request from client need carry the JWT token in header.
I would like to use Next.js only as my frontend(the server components confused me a long time).
I'm happy with everything else about Next.js so far, but I am struggling dealing with authentication and authorization on NextAuth.
Now I can call my .Net login API in NextAuth actually, and it will return the right data from .Net including JWT, username, password and etc. And NextAuth can do authentication and authorization job.
However, it seems that NextAuth will generate another JWT itself rather than using the JWT returned back from .Net. Ideally, I only want the JWT from .Net.
I know I should be able to manually store the JWT token from .Net myself and manage it by, Redux or Context and etc like in vanilla React, but the point I am confusing is that I am using NextAuth.js, is there a way that can implement what I required?
Therefor what I really want to ask is what is the best practice when using .Net as backend and Next.js as frontend for authentication and authorization?
Upvotes: 0
Views: 117