golang backend with nextjs cookie check.

I have created better auth server in my nextjs client app and want to integrate with a golang api service, but i don't know how to extract the cookie in my middleware, how to extract data from a cookie. I have tried jwt plugin as an alternate solution but still can't figure out how to extract the data correctly. I need to use cookie if possible.
5 Replies
KiNFiSH
KiNFiSH6d ago
Where is the authentication happening ?
Kaleb
KalebOP6d ago
Auth is fully happening in nextjs, what i need in my server is to check for "id" field of the cookie, and use it in my go service.
KiNFiSH
KiNFiSH6d ago
If you can get the cookie from the header in golang ..you should try parsing the header with cookie name goes by better-auth.session-token or set your own custom cookie here - https://www.better-auth.com/docs/concepts/cookies#custom-cookies
Cookies | Better Auth
Learn how cookies are used in Better Auth.
Kaleb
KalebOP6d ago
Thanks, yeah i have tried to get the cookie and extract info, but i dont know what encryption algorithms better auth is using, which means i can't get the righr library to parse the cookie with my better auth secret.
KiNFiSH
KiNFiSH6d ago
make sure to check the spec for cookie setter and getter as well - https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/cookies/index.ts and https://github.com/better-auth/utils as well for utils.
GitHub
better-auth/packages/better-auth/src/cookies/index.ts at main · be...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
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

Did you find this page helpful?