From 0d9536f103546901cb222924d71d92cb6fe9170b Mon Sep 17 00:00:00 2001 From: Hebilicious Date: Mon, 14 Aug 2023 14:21:09 +0700 Subject: [PATCH 1/3] feat(unstorage): add ttl support --- packages/adapter-session-unstorage/package.json | 2 +- packages/adapter-session-unstorage/src/unstorage.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/adapter-session-unstorage/package.json b/packages/adapter-session-unstorage/package.json index ccc20a423..52cd8edcb 100644 --- a/packages/adapter-session-unstorage/package.json +++ b/packages/adapter-session-unstorage/package.json @@ -35,7 +35,7 @@ }, "peerDependencies": { "lucia": "^2.0.0", - "unstorage": "^1.6.1" + "unstorage": "^1.9.0" }, "devDependencies": { "@lucia-auth/adapter-test": "latest", diff --git a/packages/adapter-session-unstorage/src/unstorage.ts b/packages/adapter-session-unstorage/src/unstorage.ts index df2356d2e..35832ec95 100644 --- a/packages/adapter-session-unstorage/src/unstorage.ts +++ b/packages/adapter-session-unstorage/src/unstorage.ts @@ -47,7 +47,9 @@ export const unstorageAdapter = ( const userSessionStorage = getUserSessionStorage(session.user_id); await Promise.all([ userSessionStorage.setItem(session.user_id, ""), - sessionStorage.setItem(session.id, session) + sessionStorage.setItem(session.id, session, { + ttl: Math.floor(Number(session.idle_expires) / 1000) + }) ]); }, deleteSession: async (sessionId) => { @@ -73,7 +75,9 @@ export const unstorageAdapter = ( const sessionResult = (await sessionStorage.getItem(sessionId)) ?? null; if (!sessionResult) return; const updatedSession = { ...sessionResult, ...partialSession }; - await sessionStorage.setItem(sessionId, updatedSession); + await sessionStorage.setItem(sessionId, updatedSession, { + ttl: Math.floor(Number(partialSession.idle_expires) / 1000) + }); } }; }; From 0abd43231966cfb92a5303264d73ad9967f47673 Mon Sep 17 00:00:00 2001 From: Hebilicious Date: Fri, 8 Sep 2023 02:08:10 +0700 Subject: [PATCH 2/3] chore: add auri file --- .auri/$mqai142h.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .auri/$mqai142h.md diff --git a/.auri/$mqai142h.md b/.auri/$mqai142h.md new file mode 100644 index 000000000..da68fee53 --- /dev/null +++ b/.auri/$mqai142h.md @@ -0,0 +1,6 @@ +--- +package: "@lucia-auth/adapter-session-unstorage" # package name +type: "minor" # "major", "minor", "patch" +--- + +Add ttl support to adapter-session-unstorage adapter From c9a3b095546eea3453dc51a134fa7514d4467169 Mon Sep 17 00:00:00 2001 From: pilcrowOnPaper <80624252+pilcrowOnPaper@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:27:18 +0900 Subject: [PATCH 3/3] Update .auri/$mqai142h.md --- .auri/$mqai142h.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.auri/$mqai142h.md b/.auri/$mqai142h.md index da68fee53..356e7894a 100644 --- a/.auri/$mqai142h.md +++ b/.auri/$mqai142h.md @@ -3,4 +3,4 @@ package: "@lucia-auth/adapter-session-unstorage" # package name type: "minor" # "major", "minor", "patch" --- -Add ttl support to adapter-session-unstorage adapter +Add ttl support