aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-17 02:02:27 +0900
committernsfisis <nsfisis@gmail.com>2025-03-17 02:02:27 +0900
commitab78224a0a800bc0266d91a219aae4b766c7efe7 (patch)
tree852736b6b630c1b8264c9ebf1fcf11f8ff6f6db5 /frontend
parent69ee27b644f9106b5ced1549493812a8a83410e1 (diff)
downloadiosdc-japan-2025-albatross-ab78224a0a800bc0266d91a219aae4b766c7efe7.tar.gz
iosdc-japan-2025-albatross-ab78224a0a800bc0266d91a219aae4b766c7efe7.tar.zst
iosdc-japan-2025-albatross-ab78224a0a800bc0266d91a219aae4b766c7efe7.zip
fix(frontend): recover from invalid session
Diffstat (limited to 'frontend')
-rw-r--r--frontend/app/.server/session.ts36
1 files changed, 35 insertions, 1 deletions
diff --git a/frontend/app/.server/session.ts b/frontend/app/.server/session.ts
index 2d9a652..0edcc35 100644
--- a/frontend/app/.server/session.ts
+++ b/frontend/app/.server/session.ts
@@ -8,9 +8,43 @@ export const cookieOptions = {
secrets: [process.env.ALBATROSS_COOKIE_SECRET ?? "local"],
};
-export const sessionStorage = createCookieSessionStorage({
+const innerSessionStorage = createCookieSessionStorage({
cookie: {
name: "albatross_session",
...cookieOptions,
},
});
+type InnerSessionStorage = typeof innerSessionStorage;
+
+// This class is used to recover from invalid sessions.
+// It may occur if the session had been created before the authentication library was updated.
+class RecoverableSessionStorage {
+ innerStorage: InnerSessionStorage;
+
+ constructor(innerStorage: InnerSessionStorage) {
+ this.innerStorage = innerStorage;
+ }
+
+ // If the session is invalid, return a new session.
+ // It may occur if the session had been created before the authentication library was updated.
+ getSession(...args: Parameters<InnerSessionStorage["getSession"]>) {
+ try {
+ return this.innerStorage.getSession(...args);
+ } catch (e) {
+ void e;
+ return this.innerStorage.getSession();
+ }
+ }
+
+ commitSession(...args: Parameters<InnerSessionStorage["commitSession"]>) {
+ return this.innerStorage.commitSession(...args);
+ }
+
+ destroySession(...args: Parameters<InnerSessionStorage["destroySession"]>) {
+ return this.innerStorage.destroySession(...args);
+ }
+}
+
+export const sessionStorage = new RecoverableSessionStorage(
+ innerSessionStorage,
+);