How to protect pages using Next Auth
I am really confused right now. I'm being told it's not recommended to use JWT for OAuth but I need to use JWTs to have middleware that protects routes from being exposed to unauthenticated users. So what am I supposed to do?
3 Replies
I don't think using JWT or other method of authentication changes how you protect your pages.
Are you using some auth library or something?
This is how I do it:
then I do this in the page:
Keep in mind this will add another client->server->db->server->client to your requests
So you can always keep this client-side by just adding a hook that redirects if user doesn't have the permissions
Yes I'm using next auth
I have to use JWT tokens if I'm using middleware
Cuz I can't call the db to get the secret in middleware
Thank you for sending this
I think it's a bit too complicated for me though
I might just use JWT for simplicity at this point
I think ima just use jwt tokens
i dont think its that bad