export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getting session item", key, result);
return result;
},
async setSessionItem(key: string, value: unknown) {
console.log("setting session item", key, value);
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
console.log("removing session item", key);
deleteCookie(c, key);
},
async destroySession() {
console.log("destroying session");
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});
export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getting session item", key, result);
return result;
},
async setSessionItem(key: string, value: unknown) {
console.log("setting session item", key, value);
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
console.log("removing session item", key);
deleteCookie(c, key);
},
async destroySession() {
console.log("destroying session");
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});