Using secure cookies on local dev server (running https) not working
I am need to test my application locally using https for a third party integration (unrelated to this), but I am running into an issue where my sessions are not being found after sign-in when using a local https server, using secure tokens. I tried to set the advanced useSecureCookies config to true, but that did not work. The secure cookies are being set in my browser, the sessions exist in the database, and the tokens that I am logging on the console are all lining up, however when I use the getSession hook, its returning null.
Debuggin items I have checked:
Logic for getting the session with set cookies:
const { getWebRequest } = await import('vinxi/http');
const request = getWebRequest();
const cookies = request?.headers.get('cookie') || '';
sessionResponse = await authClient.getSession({
fetchOptions: { headers: { cookie: cookies } }
});
[root] beforeLoad: Fetching session from authClient.getSession
[SSR] Raw cookie header: Secure-better-auth.session_token=<valid_token>.<signature>
[SSR] Parsed session ID: <valid_token>
[SSR] Parsed signature: <signature>
[__root] Session fetch result: { data: null, error: { status: 0, statusText: '' } }
Debuggin items I have checked:
- BETTER_AUTH_URL is being set to https://localhost:3000
- Https is working
- Tried setting useSecureCookies in the advanced config section
- Tried setting the cookiePrefix to __Secure-better-auth
Logic for getting the session with set cookies:
const { getWebRequest } = await import('vinxi/http');
const request = getWebRequest();
const cookies = request?.headers.get('cookie') || '';
sessionResponse = await authClient.getSession({
fetchOptions: { headers: { cookie: cookies } }
});
[root] beforeLoad: Fetching session from authClient.getSession
[SSR] Raw cookie header: Secure-better-auth.session_token=<valid_token>.<signature>
[SSR] Parsed session ID: <valid_token>
[SSR] Parsed signature: <signature>
[__root] Session fetch result: { data: null, error: { status: 0, statusText: '' } }