#Protect pages from a logged in user

9 messages · Page 1 of 1 (latest)

tiny hearth
#

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.

paper dawnBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
winter tartan
#

because last time i checked, the next-auth default middleware uses getToken behind the scenes, so that function is definitely edge-compatible

tiny hearth
#

I tried 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 😫 .

#

this_is_fine Thank you anyways 🙏

winter tartan
#

well... whatever happened in the past we don't need to care, as long as it works we are good

#

have fun coding

tiny hearth
#

Thank you.