diff --git a/backend/src/auth/index.ts b/backend/src/auth/index.ts index fb9463b9..161527f2 100644 --- a/backend/src/auth/index.ts +++ b/backend/src/auth/index.ts @@ -76,10 +76,6 @@ export function createAuth(db: Database) { session: { expiresIn: 60 * 60 * 24 * 7, updateAge: 60 * 60 * 24, - cookieCache: { - enabled: true, - maxAge: 60 * 5, - }, }, user: { additionalFields: { diff --git a/backend/test/auth/index.test.ts b/backend/test/auth/index.test.ts index e42f48b9..70af8bf3 100644 --- a/backend/test/auth/index.test.ts +++ b/backend/test/auth/index.test.ts @@ -119,6 +119,34 @@ describe('createAuth', () => { } }) + it('rejects a session cookie immediately after its session row is deleted', async () => { + const db = createAuthDatabase() + const auth = createAuth(db) + + try { + const signUpResponse = await auth.handler(new Request('http://localhost:5173/api/auth/sign-up/email', { + method: 'POST', + headers: { 'content-type': 'application/json', origin: 'http://localhost:5173' }, + body: JSON.stringify({ email: 'revoked@example.com', password: 'test-password', name: 'Revoked' }), + })) + expect(signUpResponse.status).toBe(200) + + const setCookies = signUpResponse.headers.getSetCookie() + expect(setCookies.length).toBeGreaterThan(0) + const headers = new Headers({ cookie: setCookies.map((cookie) => cookie.split(';')[0]).join('; ') }) + + const session = await auth.api.getSession({ headers }) + expect(session?.user.email).toBe('revoked@example.com') + + db.prepare('DELETE FROM "session" WHERE "userId" = ?').run(session!.user.id) + expect(db.prepare('SELECT COUNT(*) AS count FROM "session"').get()).toEqual({ count: 0 }) + + expect(await auth.api.getSession({ headers })).toBeNull() + } finally { + db.close() + } + }, 30000) + it('creates an auth instance without social providers and responds to requests', async () => { const db = createAuthDatabase() const auth = createAuth(db)