`auth.api.getSession` returns null when headers from `auth.api.signInEmail` passed to it
I am trying to build a provisioning where I (SaaS provider) provisions an org and a user for a customer.
I want to use
here is a code snippet currently testing with plain node then I will port it to an express route
here is what is logged:
yet still unable to get session
I want to use
better-auth-extended/app-invite (https://www.npmjs.com/package/@better-auth-extended/app-invite) for provisioning the user however that was not working after some debugging I found out that the session is being returned as nullhere is a code snippet currently testing with plain node then I will port it to an express route
here is what is logged:
userHeaders does have a value that I am passing to auth.api.getSession and I have confirmed the session table in the db has a row with the token same as shownyet still unable to get session
Solution
i solved it by looking at the
rather than passing
this is because
https://github.com/Bekacru/better-call/blob/638acd821f03cdb7016b3e4784092eef42b4cbbc/src/context.ts#L199
signInWithTestUser in test-utils https://github.com/better-auth/better-auth/blob/bcfd3c335cbbcee620499adca6592d86e8f4d933/packages/better-auth/src/test-utils/test-instance.ts#L236-L239rather than passing
userHeaders I changed it tothis is because
better-call's createInternalContext gets the cookie from the cookie header not set-cookie headerhttps://github.com/Bekacru/better-call/blob/638acd821f03cdb7016b3e4784092eef42b4cbbc/src/context.ts#L199
GitHub
a tiny web framework for typescript. Contribute to Bekacru/better-call development by creating an account on GitHub.
GitHub
The most comprehensive authentication framework for TypeScript - better-auth/better-auth