| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | import { createCookie, isCookie } from "../cookies.js";
|
| 12 | import { createSession, warnOnceAboutSigningSessionCookie } from "../sessions.js";
|
| 13 |
|
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 |
|
| 23 | function createCookieSessionStorage({ cookie: cookieArg } = {}) {
|
| 24 | let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
|
| 25 | warnOnceAboutSigningSessionCookie(cookie);
|
| 26 | return {
|
| 27 | async getSession(cookieHeader, options) {
|
| 28 | return createSession(cookieHeader && await cookie.parse(cookieHeader, options) || {});
|
| 29 | },
|
| 30 | async commitSession(session, options) {
|
| 31 | let serializedCookie = await cookie.serialize(session.data, options);
|
| 32 | if (serializedCookie.length > 4096) throw new Error("Cookie length will exceed browser maximum. Length: " + serializedCookie.length);
|
| 33 | return serializedCookie;
|
| 34 | },
|
| 35 | async destroySession(_session, options) {
|
| 36 | return cookie.serialize("", {
|
| 37 | ...options,
|
| 38 | maxAge: void 0,
|
| 39 | expires: new Date(0)
|
| 40 | });
|
| 41 | }
|
| 42 | };
|
| 43 | }
|
| 44 |
|
| 45 | export { createCookieSessionStorage };
|