Manually create a session
Hi, for testing purposes I want to create a session in my own controller, and set the right cookies. Although, it seems like the sesison token has to be in a certain structure. Has anyone got a better idea on how I can implement this?
The cookie names do match, I am using NextJS so I would need a backend approach to create the sessions.
Solution:Jump to solution
hmm...you can fill it with those details -
```ts
import { createRandomStringGenerator } from "@better-auth/utils/random";
import { createHMAC } from "@better-auth/utils/hmac";...
GitHub
GitHub - better-auth/utils: A simple typescript API for common auth...
A simple typescript API for common auth related operations built on top of Web Crypto API. - better-auth/utils
4 Replies
😇
😦
Solution
hmm...you can fill it with those details -
this is what the better auth does internally .. for more utils please make sure to visit https://github.com/better-auth/utils
GitHub
GitHub - better-auth/utils: A simple typescript API for common auth...
A simple typescript API for common auth related operations built on top of Web Crypto API. - better-auth/utils
Ahhh thanks!! I wasn't aware of the signing 😮
Hey,
I’m in a similar situation where I need to create the Session manually. The biggest problem is session cookie. What should i do after using generateId(32) and createHMAC(…)
If i check the cookie created by using the api method signInEmail, then it’s in a format: token.signature
How do i get the correct signature?
Because providing the signedToken given by createHMAC directly to the auth.api.getSession always returns null.
What I’m missing here?