enzostvs HF Staff commited on
Commit
ebe891e
·
1 Parent(s): 8719403

cookie options

Browse files
Files changed (1) hide show
  1. lib/cookie-options.ts +47 -0
lib/cookie-options.ts ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Cookie options for iframe compatibility using CHIPS (Cookies Having Independent Partitioned State)
2
+ export interface IframeCookieOptions {
3
+ expires?: Date;
4
+ maxAge?: number;
5
+ sameSite?: "strict" | "lax" | "none";
6
+ secure?: boolean;
7
+ partitioned?: boolean;
8
+ domain?: string;
9
+ path?: string;
10
+ }
11
+
12
+ /**
13
+ * Get cookie options optimized for iframe usage
14
+ * Uses CHIPS (Cookies Having Independent Partitioned State) for cross-site cookie support
15
+ */
16
+ export function getIframeCookieOptions(
17
+ customOptions: Partial<IframeCookieOptions> = {}
18
+ ): IframeCookieOptions {
19
+ return {
20
+ sameSite: "none",
21
+ secure: true,
22
+ partitioned: true,
23
+ path: "/",
24
+ ...customOptions,
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Get cookie options for the auth token specifically
30
+ */
31
+ export function getAuthCookieOptions(expiresIn?: number): IframeCookieOptions {
32
+ return getIframeCookieOptions({
33
+ expires: expiresIn
34
+ ? new Date(Date.now() + expiresIn * 1000)
35
+ : undefined,
36
+ });
37
+ }
38
+
39
+ /**
40
+ * Get cookie options for removing iframe-compatible cookies
41
+ * Sets the cookie to expire immediately while maintaining the same attributes
42
+ */
43
+ export function getRemoveCookieOptions(): IframeCookieOptions {
44
+ return getIframeCookieOptions({
45
+ expires: new Date(0), // Set to epoch time (expired)
46
+ });
47
+ }