Protect pages from a logged in user
Answered
Bigheaded ant posted this in #help-forum
Bigheaded antOP
Hi, I can't my wrap my head around how I can redirect users from login or register page to home if they are logged in already. I want to do this via a middleware. I tried to use
I also used next-auth middleware but i am only able to protect pages from unauthenticated users not the opposite.
getServerSession but that does not work in middleware.I also used next-auth middleware but i am only able to protect pages from unauthenticated users not the opposite.
7 Replies
@Bigheaded ant Hi, I can't my wrap my head around how I can redirect users from login or register page to home if they are logged in already. I want to do this via a middleware. I tried to use `getServerSession` but that does not work in middleware.
I also used next-auth middleware but i am only able to protect pages from unauthenticated users not the opposite.
use
getToken it should work for middlewareAnswer
because last time i checked, the next-auth default middleware uses
getToken behind the scenes, so that function is definitely edge-compatibleBigheaded antOP
I tried
I don't know if this next framework has inconsistencies or I am going insane. I feel so mentally exhausted 😫 .
getToken before but it kept giving me null now i tried again on your suggestion and it works.I don't know if this next framework has inconsistencies or I am going insane. I feel so mentally exhausted 😫 .
Thank you anyways ðŸ™well... whatever happened in the past we don't need to care, as long as it works we are good
have fun coding
Bigheaded antOP
Thank you.