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:
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
Jump to solution
9 Replies
korrupt10n
korrupt10nOP•5w ago
is anyone able to help with this?
Anup
Anup•5w ago
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
korrupt10n
korrupt10n•5w ago
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
milan
milan•2w ago
@korrupt10n I'm facing the same issue, getSession always returns null - how did you fix it?
korrupt10n
korrupt10nOP•2w ago
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
milan
milan•2w ago
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
korrupt10n
korrupt10nOP•2w ago
can you share more information then
milan
milan•2w ago
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
korrupt10n
korrupt10nOP•2w ago
ah okay, are you able to see the cookies on the browser?

Did you find this page helpful?