From 60a9148bcaa42bc261d1c1f4c3c4e3b642d29c4f Mon Sep 17 00:00:00 2001 From: Sabine Schaller Date: Wed, 7 Aug 2024 15:00:19 +0200 Subject: [PATCH] fix(auth): interact redirect (#2832) * fix(auth): interact redirect * fix(auth): session cookie not expiring in browser * fix(auth): session expiration time unit --------- Co-authored-by: Blair Currey <12960453+BlairCurrey@users.noreply.github.com> --- packages/auth/src/app.ts | 25 +++++++++---------------- packages/auth/src/interaction/routes.ts | 1 - 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/auth/src/app.ts b/packages/auth/src/app.ts index 191cba8120..a70d438e24 100644 --- a/packages/auth/src/app.ts +++ b/packages/auth/src/app.ts @@ -353,18 +353,22 @@ export class App { signed: true, store: { async get(key) { - return await redis.hgetall(key) + const s = await redis.get(key) + + if (!s) return null + + return JSON.parse(s) }, async set(key, session) { // Add a delay to cookie age to ensure redis record expires after cookie - const expireInMs = maxAgeMs + 10 * 1000 + const expireInSec = maxAgeMs / 1000 + 10 const op = redis.multi() - op.hset(key, session) - op.expire(key, expireInMs) + op.set(key, JSON.stringify(session)) + op.expire(key, expireInSec) await op.exec() }, async destroy(key) { - await redis.hdel(key) + await redis.del(key) } } }, @@ -441,17 +445,6 @@ export class App { koa.use(cors()) koa.keys = [this.config.cookieKey] - koa.use( - session( - { - key: 'sessionId', - maxAge: 60 * 1000, - signed: true - }, - koa - ) - ) - koa.use(router.middleware()) koa.use(router.routes()) diff --git a/packages/auth/src/interaction/routes.ts b/packages/auth/src/interaction/routes.ts index 8f29ea9fa5..6eb3f5dcff 100644 --- a/packages/auth/src/interaction/routes.ts +++ b/packages/auth/src/interaction/routes.ts @@ -181,7 +181,6 @@ async function startInteraction( const trx = await Interaction.startTransaction() try { - // TODO: also establish session in redis with short expiry await grantService.markPending(interaction.id, trx) await trx.commit()