Skip to content

Commit

Permalink
feat(unstorage): add ttl support (#970)
Browse files Browse the repository at this point in the history
Co-authored-by: pilcrowOnPaper <[email protected]>
  • Loading branch information
Hebilicious and pilcrowonpaper authored Sep 9, 2023
1 parent e4dc22a commit 904dbe3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .auri/$mqai142h.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
package: "@lucia-auth/adapter-session-unstorage" # package name
type: "minor" # "major", "minor", "patch"
---

Add ttl support
2 changes: 1 addition & 1 deletion packages/adapter-session-unstorage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"peerDependencies": {
"lucia": "^2.0.0",
"unstorage": "^1.6.1"
"unstorage": "^1.9.0"
},
"devDependencies": {
"@lucia-auth/adapter-test": "latest",
Expand Down
8 changes: 6 additions & 2 deletions packages/adapter-session-unstorage/src/unstorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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) => {
Expand All @@ -77,7 +79,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)
});
}
};
};
Expand Down

0 comments on commit 904dbe3

Please sign in to comment.