fix: last auth provider cookie (wrong domain)

This commit is contained in:
Carl-Gerhard Lindesvärd
2026-02-27 23:41:38 +01:00
parent 1272466235
commit b801d6a8ef
3 changed files with 22 additions and 16 deletions

View File

@@ -7,7 +7,17 @@ export function setSessionTokenCookie(
expiresAt: Date
): void {
setCookie('session', token, {
maxAge: Math.floor((expiresAt.getTime() - new Date().getTime()) / 1000),
maxAge: Math.floor((expiresAt.getTime() - Date.now()) / 1000),
...COOKIE_OPTIONS,
});
}
export function setLastAuthProviderCookie(
setCookie: ISetCookie,
provider: string
): void {
setCookie('last-auth-provider', provider, {
maxAge: 60 * 60 * 24 * 365,
...COOKIE_OPTIONS,
});
}

View File

@@ -8,6 +8,7 @@ import {
google,
hashPassword,
invalidateSession,
setLastAuthProviderCookie,
setSessionTokenCookie,
validateSessionToken,
verifyPasswordHash,
@@ -225,11 +226,7 @@ export const authRouter = createTRPCRouter({
const token = generateSessionToken();
const session = await createSession(token, user.id);
setSessionTokenCookie(ctx.setCookie, token, session.expiresAt);
ctx.setCookie('last-auth-provider', 'email', {
maxAge: 60 * 60 * 24 * 365,
path: '/',
sameSite: 'lax',
});
setLastAuthProviderCookie(ctx.setCookie, 'email');
return {
type: 'email',
};