Skip to content

Commit abacbfe

Browse files
committed
cookie store: allow explicit domain
1 parent a220db2 commit abacbfe

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/CookieSessionStore.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SessionStore } from "./types";
22

33
export interface CookieSessionStoreOptions {
4+
domain?: string;
45
path?: string;
56
sameSite?: "Lax" | "Strict" | "None";
67
useExplicitExpiry?: boolean;
@@ -12,14 +13,14 @@ export default class CookieSessionStore implements SessionStore {
1213
private readonly path: string;
1314
private readonly sameSite: string;
1415
private readonly useExplicitExpiry: boolean;
16+
private readonly domain: string;
1517

1618
constructor(cookieName: string, opts: CookieSessionStoreOptions = {}) {
1719
this.sessionName = cookieName;
18-
1920
this.path = !!opts.path ? `; path=${opts.path}` : "";
21+
this.domain = !!opts.domain ? `; domain=${opts.domain}` : "";
2022
this.sameSite = !!opts.sameSite ? `; SameSite=${opts.sameSite}` : "";
2123
this.useExplicitExpiry = !!opts.useExplicitExpiry;
22-
2324
if (typeof window !== "undefined") {
2425
this.secureFlag = window.location.protocol === "https:" ? "; secure" : "";
2526
}
@@ -44,7 +45,7 @@ export default class CookieSessionStore implements SessionStore {
4445
expiresDate.setTime(exp);
4546
expires = `; expires=${expiresDate.toUTCString()}`;
4647
}
47-
document.cookie = `${this.sessionName}=${val}${this.secureFlag}${expires}${this.path}${this.sameSite}`;
48+
document.cookie = `${this.sessionName}=${val}${this.secureFlag}${expires}${this.path}${this.sameSite}${this.domain}`;
4849
}
4950
}
5051

0 commit comments

Comments
 (0)