Back

[SOLVED] user session is created, but `currentUser` still returns null

  • 0
  • Users
  • Web
Drake
23 Sep, 2023, 18:04

Are you able to see the network request details

TL;DR
Title: [SOLVED] User session created but `currentUser` returns null in Next.js Solution: The issue was caused by the middleware redirecting the `/auth/oauth2/success` path before its code could be executed. To fix it, the `/auth/oauth2/success` path should be added as a public route in the middleware. Additionally, manually handling cookies in the `/auth/oauth2/success` path resolved the problem.
manazo
23 Sep, 2023, 18:06

this?

Drake
23 Sep, 2023, 18:09

No the account.get() call

Drake
23 Sep, 2023, 18:09

Is it the last session cookie that came from Appwrite?

manazo
23 Sep, 2023, 18:33

it gets called on page load by the middleware. so can't specify it from the console

manazo
23 Sep, 2023, 18:33

what do u mean by the last session cookie?

Drake
23 Sep, 2023, 18:34

The last time you created the email session.

manazo
23 Sep, 2023, 18:38

maybe i'm too noob to understand what u saying. do u want me to remove the middleware code and do a successful login, and then again add the middleware code and then compare the before and after cookie values?

Drake
23 Sep, 2023, 18:39

Sure that could work.

Or you can manually try to use that cookie value to make the request

manazo
23 Sep, 2023, 18:42

yoo... they aren't same😐

Drake
23 Sep, 2023, 18:44

That's not good. Maybe the value in your middleware is an old deleted session and that's why you're getting the error

manazo
23 Sep, 2023, 18:46

sad... how can i solve this?

Drake
23 Sep, 2023, 19:15

Are you making sure to clear things as necessary?

manazo
23 Sep, 2023, 20:40

clear things as necessary? didn't get it

Drake
23 Sep, 2023, 20:50

For example, deleting the cookie if it's not valid anymore

manazo
23 Sep, 2023, 20:52

i'm deleting the cookies only when the user logs out. do i need to do anything more?

Drake
23 Sep, 2023, 20:53

Maybe it's not getting deleted in all places or something. I don't know. I hate nextjs

manazo
23 Sep, 2023, 21:04

after some digging, i found that when the middleware is on, we are not setting any new cookie value. till now what i was seeing was the cookie from the last session

Drake
23 Sep, 2023, 21:05

Again...I hate nextjs 🤣

manazo
23 Sep, 2023, 21:06

and after your suggestion on another post of mine, i handled the cookies manually in the /auth/oauth2/success path

manazo
23 Sep, 2023, 21:08

that means my middleware is redirecting it from /auth/oauth2/success to / before the code of /auth/oauth2/success gets executed

manazo
23 Sep, 2023, 21:09

okay, so I just found out I'm nothing but dumb. i had to add /auth/oauth2/success as a public route in the middleware

manazo
23 Sep, 2023, 21:10

don't hate nextjs. hate me🙂

manazo
23 Sep, 2023, 22:36

[SOLVED] user session is created, but currentUser still returns null

Drake
23 Sep, 2023, 22:42

Still hate nextjs because of all these gotchas 😜 I'm glad you figured it out <:appwriteparty:946072712915341333>

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more