authClient.GetSessions() returning null for user data and session data
I have an issue where getsessions function of the authClient is returning null. I am trying to sign up/in a user with google. The auth flow seems to work ie I get a session, user and account stored in my database. I also get the onsuccess handler called after signIn. The issue is, the data is null ie const {data} = authClient.getSession(). I am trying to read the userid so I can send other requests to the database.
Here is my auth context handler: https://github.com/zessu/honoapp/blob/master/packages/frontend/src/authContext.tsx issue on line 22
Here is the backend Auth config
https://github.com/zessu/honoapp/blob/master/packages/backend/auth.ts
And here is the index route
https://github.com/zessu/honoapp/blob/master/packages/backend/index.ts
So, why is this null? Also, should I even be reading user information data e.g sessionId on the frontend or should I just read it from the server?
GitHub
honoapp/packages/frontend/src/authContext.tsx at master · zessu/hon...
Expense Tracker - react, tailwind, daisy-ui, drizzle, tanstack query, tanstack router, react-hook-form, supabase, bun, hono, postgresql, docker, better-auth - zessu/honoapp
GitHub
honoapp/packages/backend/auth.ts at master · zessu/honoapp
Expense Tracker - react, tailwind, daisy-ui, drizzle, tanstack query, tanstack router, react-hook-form, supabase, bun, hono, postgresql, docker, better-auth - zessu/honoapp
GitHub
honoapp/packages/backend/index.ts at master · zessu/honoapp
Expense Tracker - react, tailwind, daisy-ui, drizzle, tanstack query, tanstack router, react-hook-form, supabase, bun, hono, postgresql, docker, better-auth - zessu/honoapp
Solution:Jump to solution
I fixed this. Issue was with the cookie settings , specifically domain settings thats why it was not being returned Anyone let me know if you have a similar issue I can try help
9 Replies
is anyone able to help with this?
GitHub
Nextjs ERR_STREAM_WRITE_AFTER_END (when Rewrite Redirect 302) v1.2....
What version of Bun is running? 1.2.6 What platform is your computer? linux-amd64 What steps can reproduce the bug? Next: 15.2.4 Rewrite: 1 api will response 302 If start with bun: Response will re...
Solution
I fixed this. Issue was with the cookie settings , specifically domain settings thats why it was not being returned Anyone let me know if you have a similar issue I can try help
@korrupt10n I'm facing the same issue, getSession always returns
null
- how did you fix it?I think this was happening cause of the domain settings, check the domain settings and confirm you have allowed your domain access to the cookie. Or, post a link to a github or something I can take a look
I checked the cookie domain setting and cross-referenced it with you have in https://github.com/zessu/honoapp/blob/master/packages/backend/auth.ts it all seems fine; I can even see the cookie in the browser console
GitHub
honoapp/packages/backend/auth.ts at master · zessu/honoapp
Expense Tracker - react, tailwind, daisy-ui, drizzle, tanstack query, tanstack router, react-hook-form, supabase, bun, hono, postgresql, docker, better-auth - zessu/honoapp
can you share more information then
not really, it's a private app and currently in a very messy state 😅 thanks anyway, I'll just put more console.logs in the code and try to find the issue
ah okay, are you able to see the cookies on the browser?