mailsentry-auth 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +28 -9
- package/dist/index.mjs +28 -9
- package/dist/middleware.mjs +35 -12
- package/dist/utils/cookie-utils.js +28 -9
- package/dist/utils/cookie-utils.mjs +28 -9
- package/package.json +20 -18
package/dist/index.d.mts
CHANGED
|
@@ -686,11 +686,12 @@ declare class CookieUtils {
|
|
|
686
686
|
* Get the refresh token cookie key from environment variables
|
|
687
687
|
*/
|
|
688
688
|
static getRefreshTokenKey(): string;
|
|
689
|
-
private static readonly COOKIE_DOMAIN;
|
|
690
689
|
/**
|
|
691
690
|
* Get root domain for subdomain support
|
|
691
|
+
* Must match the domain used by backend when setting cookies
|
|
692
692
|
*/
|
|
693
693
|
private static getRootDomain;
|
|
694
|
+
private static readonly COOKIE_DOMAIN;
|
|
694
695
|
/**
|
|
695
696
|
* Get common cookie options
|
|
696
697
|
*/
|
|
@@ -732,6 +733,7 @@ declare class CookieUtils {
|
|
|
732
733
|
}>;
|
|
733
734
|
/**
|
|
734
735
|
* Clear all authentication cookies (client-side only)
|
|
736
|
+
* Clears cookies from both current domain and root domain
|
|
735
737
|
*/
|
|
736
738
|
static clearAuthCookies(): void;
|
|
737
739
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -686,11 +686,12 @@ declare class CookieUtils {
|
|
|
686
686
|
* Get the refresh token cookie key from environment variables
|
|
687
687
|
*/
|
|
688
688
|
static getRefreshTokenKey(): string;
|
|
689
|
-
private static readonly COOKIE_DOMAIN;
|
|
690
689
|
/**
|
|
691
690
|
* Get root domain for subdomain support
|
|
691
|
+
* Must match the domain used by backend when setting cookies
|
|
692
692
|
*/
|
|
693
693
|
private static getRootDomain;
|
|
694
|
+
private static readonly COOKIE_DOMAIN;
|
|
694
695
|
/**
|
|
695
696
|
* Get common cookie options
|
|
696
697
|
*/
|
|
@@ -732,6 +733,7 @@ declare class CookieUtils {
|
|
|
732
733
|
}>;
|
|
733
734
|
/**
|
|
734
735
|
* Clear all authentication cookies (client-side only)
|
|
736
|
+
* Clears cookies from both current domain and root domain
|
|
735
737
|
*/
|
|
736
738
|
static clearAuthCookies(): void;
|
|
737
739
|
/**
|
package/dist/index.js
CHANGED
|
@@ -420,12 +420,18 @@ var _CookieUtils = class _CookieUtils {
|
|
|
420
420
|
static getRefreshTokenKey() {
|
|
421
421
|
return process.env.AUTH_REFRESH_TOKEN_KEY || "auth_refresh_token";
|
|
422
422
|
}
|
|
423
|
-
// Use current domain in development
|
|
424
423
|
/**
|
|
425
424
|
* Get root domain for subdomain support
|
|
425
|
+
* Must match the domain used by backend when setting cookies
|
|
426
426
|
*/
|
|
427
427
|
static getRootDomain() {
|
|
428
|
-
if (typeof window === "undefined")
|
|
428
|
+
if (typeof window === "undefined") {
|
|
429
|
+
const baseDomain = process.env.NEXT_PUBLIC_BASE_DOMAIN;
|
|
430
|
+
if (baseDomain && process.env.NODE_ENV === "production") {
|
|
431
|
+
return `.${baseDomain}`;
|
|
432
|
+
}
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
429
435
|
const hostname = window.location.hostname;
|
|
430
436
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
431
437
|
return void 0;
|
|
@@ -439,13 +445,15 @@ var _CookieUtils = class _CookieUtils {
|
|
|
439
445
|
}
|
|
440
446
|
return void 0;
|
|
441
447
|
}
|
|
448
|
+
// Use current domain in development
|
|
442
449
|
/**
|
|
443
450
|
* Get common cookie options
|
|
444
451
|
*/
|
|
445
452
|
static getCookieOptions() {
|
|
446
453
|
return {
|
|
447
454
|
path: "/",
|
|
448
|
-
sameSite: "
|
|
455
|
+
sameSite: "lax",
|
|
456
|
+
// Changed from 'strict' to 'lax' for cross-subdomain
|
|
449
457
|
secure: process.env.NODE_ENV === "production",
|
|
450
458
|
// Only secure in production
|
|
451
459
|
domain: this.COOKIE_DOMAIN
|
|
@@ -535,18 +543,26 @@ var _CookieUtils = class _CookieUtils {
|
|
|
535
543
|
}
|
|
536
544
|
/**
|
|
537
545
|
* Clear all authentication cookies (client-side only)
|
|
546
|
+
* Clears cookies from both current domain and root domain
|
|
538
547
|
*/
|
|
539
548
|
static clearAuthCookies() {
|
|
540
549
|
if (this.isServerSide()) {
|
|
541
550
|
console.warn("clearAuthCookies called on server side - use server actions instead");
|
|
542
551
|
return;
|
|
543
552
|
}
|
|
544
|
-
const
|
|
553
|
+
const accessKey = this.getAccessTokenKey();
|
|
554
|
+
const refreshKey = this.getRefreshTokenKey();
|
|
555
|
+
const rootDomainOptions = {
|
|
545
556
|
path: "/",
|
|
546
557
|
domain: this.COOKIE_DOMAIN
|
|
547
558
|
};
|
|
548
|
-
api.remove(
|
|
549
|
-
api.remove(
|
|
559
|
+
api.remove(accessKey, rootDomainOptions);
|
|
560
|
+
api.remove(refreshKey, rootDomainOptions);
|
|
561
|
+
const currentDomainOptions = {
|
|
562
|
+
path: "/"
|
|
563
|
+
};
|
|
564
|
+
api.remove(accessKey, currentDomainOptions);
|
|
565
|
+
api.remove(refreshKey, currentDomainOptions);
|
|
550
566
|
}
|
|
551
567
|
/**
|
|
552
568
|
* Check if cookies are supported/enabled (client-side only)
|
|
@@ -613,18 +629,21 @@ var _CookieUtils = class _CookieUtils {
|
|
|
613
629
|
return {
|
|
614
630
|
error: "Server-side rendering - no domain info available",
|
|
615
631
|
environment: process.env.NODE_ENV || "unknown",
|
|
632
|
+
cookieDomain: this.COOKIE_DOMAIN || "undefined",
|
|
633
|
+
baseDomain: process.env.NEXT_PUBLIC_BASE_DOMAIN || "undefined",
|
|
616
634
|
recommendation: "Use server actions for server-side cookie access"
|
|
617
635
|
};
|
|
618
636
|
}
|
|
619
637
|
return {
|
|
620
638
|
hostname: window.location.hostname,
|
|
621
|
-
|
|
639
|
+
cookieDomain: this.COOKIE_DOMAIN || "current domain",
|
|
622
640
|
environment: process.env.NODE_ENV || "unknown",
|
|
623
|
-
protocol: window.location.protocol
|
|
641
|
+
protocol: window.location.protocol,
|
|
642
|
+
sameSite: "lax"
|
|
624
643
|
};
|
|
625
644
|
}
|
|
626
645
|
};
|
|
627
|
-
// Domain configuration
|
|
646
|
+
// Domain configuration - computed once
|
|
628
647
|
_CookieUtils.COOKIE_DOMAIN = process.env.NODE_ENV === "production" ? _CookieUtils.getRootDomain() : void 0;
|
|
629
648
|
var CookieUtils = _CookieUtils;
|
|
630
649
|
|
package/dist/index.mjs
CHANGED
|
@@ -420,12 +420,18 @@ var _CookieUtils = class _CookieUtils {
|
|
|
420
420
|
static getRefreshTokenKey() {
|
|
421
421
|
return process.env.AUTH_REFRESH_TOKEN_KEY || "auth_refresh_token";
|
|
422
422
|
}
|
|
423
|
-
// Use current domain in development
|
|
424
423
|
/**
|
|
425
424
|
* Get root domain for subdomain support
|
|
425
|
+
* Must match the domain used by backend when setting cookies
|
|
426
426
|
*/
|
|
427
427
|
static getRootDomain() {
|
|
428
|
-
if (typeof window === "undefined")
|
|
428
|
+
if (typeof window === "undefined") {
|
|
429
|
+
const baseDomain = process.env.NEXT_PUBLIC_BASE_DOMAIN;
|
|
430
|
+
if (baseDomain && process.env.NODE_ENV === "production") {
|
|
431
|
+
return `.${baseDomain}`;
|
|
432
|
+
}
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
429
435
|
const hostname = window.location.hostname;
|
|
430
436
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
431
437
|
return void 0;
|
|
@@ -439,13 +445,15 @@ var _CookieUtils = class _CookieUtils {
|
|
|
439
445
|
}
|
|
440
446
|
return void 0;
|
|
441
447
|
}
|
|
448
|
+
// Use current domain in development
|
|
442
449
|
/**
|
|
443
450
|
* Get common cookie options
|
|
444
451
|
*/
|
|
445
452
|
static getCookieOptions() {
|
|
446
453
|
return {
|
|
447
454
|
path: "/",
|
|
448
|
-
sameSite: "
|
|
455
|
+
sameSite: "lax",
|
|
456
|
+
// Changed from 'strict' to 'lax' for cross-subdomain
|
|
449
457
|
secure: process.env.NODE_ENV === "production",
|
|
450
458
|
// Only secure in production
|
|
451
459
|
domain: this.COOKIE_DOMAIN
|
|
@@ -535,18 +543,26 @@ var _CookieUtils = class _CookieUtils {
|
|
|
535
543
|
}
|
|
536
544
|
/**
|
|
537
545
|
* Clear all authentication cookies (client-side only)
|
|
546
|
+
* Clears cookies from both current domain and root domain
|
|
538
547
|
*/
|
|
539
548
|
static clearAuthCookies() {
|
|
540
549
|
if (this.isServerSide()) {
|
|
541
550
|
console.warn("clearAuthCookies called on server side - use server actions instead");
|
|
542
551
|
return;
|
|
543
552
|
}
|
|
544
|
-
const
|
|
553
|
+
const accessKey = this.getAccessTokenKey();
|
|
554
|
+
const refreshKey = this.getRefreshTokenKey();
|
|
555
|
+
const rootDomainOptions = {
|
|
545
556
|
path: "/",
|
|
546
557
|
domain: this.COOKIE_DOMAIN
|
|
547
558
|
};
|
|
548
|
-
api.remove(
|
|
549
|
-
api.remove(
|
|
559
|
+
api.remove(accessKey, rootDomainOptions);
|
|
560
|
+
api.remove(refreshKey, rootDomainOptions);
|
|
561
|
+
const currentDomainOptions = {
|
|
562
|
+
path: "/"
|
|
563
|
+
};
|
|
564
|
+
api.remove(accessKey, currentDomainOptions);
|
|
565
|
+
api.remove(refreshKey, currentDomainOptions);
|
|
550
566
|
}
|
|
551
567
|
/**
|
|
552
568
|
* Check if cookies are supported/enabled (client-side only)
|
|
@@ -613,18 +629,21 @@ var _CookieUtils = class _CookieUtils {
|
|
|
613
629
|
return {
|
|
614
630
|
error: "Server-side rendering - no domain info available",
|
|
615
631
|
environment: process.env.NODE_ENV || "unknown",
|
|
632
|
+
cookieDomain: this.COOKIE_DOMAIN || "undefined",
|
|
633
|
+
baseDomain: process.env.NEXT_PUBLIC_BASE_DOMAIN || "undefined",
|
|
616
634
|
recommendation: "Use server actions for server-side cookie access"
|
|
617
635
|
};
|
|
618
636
|
}
|
|
619
637
|
return {
|
|
620
638
|
hostname: window.location.hostname,
|
|
621
|
-
|
|
639
|
+
cookieDomain: this.COOKIE_DOMAIN || "current domain",
|
|
622
640
|
environment: process.env.NODE_ENV || "unknown",
|
|
623
|
-
protocol: window.location.protocol
|
|
641
|
+
protocol: window.location.protocol,
|
|
642
|
+
sameSite: "lax"
|
|
624
643
|
};
|
|
625
644
|
}
|
|
626
645
|
};
|
|
627
|
-
// Domain configuration
|
|
646
|
+
// Domain configuration - computed once
|
|
628
647
|
_CookieUtils.COOKIE_DOMAIN = process.env.NODE_ENV === "production" ? _CookieUtils.getRootDomain() : void 0;
|
|
629
648
|
var CookieUtils = _CookieUtils;
|
|
630
649
|
|
package/dist/middleware.mjs
CHANGED
|
@@ -86,12 +86,18 @@ var _CookieUtils = class _CookieUtils {
|
|
|
86
86
|
static getRefreshTokenKey() {
|
|
87
87
|
return process.env.AUTH_REFRESH_TOKEN_KEY || "auth_refresh_token";
|
|
88
88
|
}
|
|
89
|
-
// Use current domain in development
|
|
90
89
|
/**
|
|
91
90
|
* Get root domain for subdomain support
|
|
91
|
+
* Must match the domain used by backend when setting cookies
|
|
92
92
|
*/
|
|
93
93
|
static getRootDomain() {
|
|
94
|
-
if (typeof window === "undefined")
|
|
94
|
+
if (typeof window === "undefined") {
|
|
95
|
+
const baseDomain = process.env.NEXT_PUBLIC_BASE_DOMAIN;
|
|
96
|
+
if (baseDomain && process.env.NODE_ENV === "production") {
|
|
97
|
+
return `.${baseDomain}`;
|
|
98
|
+
}
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
95
101
|
const hostname = window.location.hostname;
|
|
96
102
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
97
103
|
return void 0;
|
|
@@ -105,13 +111,15 @@ var _CookieUtils = class _CookieUtils {
|
|
|
105
111
|
}
|
|
106
112
|
return void 0;
|
|
107
113
|
}
|
|
114
|
+
// Use current domain in development
|
|
108
115
|
/**
|
|
109
116
|
* Get common cookie options
|
|
110
117
|
*/
|
|
111
118
|
static getCookieOptions() {
|
|
112
119
|
return {
|
|
113
120
|
path: "/",
|
|
114
|
-
sameSite: "
|
|
121
|
+
sameSite: "lax",
|
|
122
|
+
// Changed from 'strict' to 'lax' for cross-subdomain
|
|
115
123
|
secure: process.env.NODE_ENV === "production",
|
|
116
124
|
// Only secure in production
|
|
117
125
|
domain: this.COOKIE_DOMAIN
|
|
@@ -201,18 +209,26 @@ var _CookieUtils = class _CookieUtils {
|
|
|
201
209
|
}
|
|
202
210
|
/**
|
|
203
211
|
* Clear all authentication cookies (client-side only)
|
|
212
|
+
* Clears cookies from both current domain and root domain
|
|
204
213
|
*/
|
|
205
214
|
static clearAuthCookies() {
|
|
206
215
|
if (this.isServerSide()) {
|
|
207
216
|
console.warn("clearAuthCookies called on server side - use server actions instead");
|
|
208
217
|
return;
|
|
209
218
|
}
|
|
210
|
-
const
|
|
219
|
+
const accessKey = this.getAccessTokenKey();
|
|
220
|
+
const refreshKey = this.getRefreshTokenKey();
|
|
221
|
+
const rootDomainOptions = {
|
|
211
222
|
path: "/",
|
|
212
223
|
domain: this.COOKIE_DOMAIN
|
|
213
224
|
};
|
|
214
|
-
Cookies.remove(
|
|
215
|
-
Cookies.remove(
|
|
225
|
+
Cookies.remove(accessKey, rootDomainOptions);
|
|
226
|
+
Cookies.remove(refreshKey, rootDomainOptions);
|
|
227
|
+
const currentDomainOptions = {
|
|
228
|
+
path: "/"
|
|
229
|
+
};
|
|
230
|
+
Cookies.remove(accessKey, currentDomainOptions);
|
|
231
|
+
Cookies.remove(refreshKey, currentDomainOptions);
|
|
216
232
|
}
|
|
217
233
|
/**
|
|
218
234
|
* Check if cookies are supported/enabled (client-side only)
|
|
@@ -279,18 +295,21 @@ var _CookieUtils = class _CookieUtils {
|
|
|
279
295
|
return {
|
|
280
296
|
error: "Server-side rendering - no domain info available",
|
|
281
297
|
environment: process.env.NODE_ENV || "unknown",
|
|
298
|
+
cookieDomain: this.COOKIE_DOMAIN || "undefined",
|
|
299
|
+
baseDomain: process.env.NEXT_PUBLIC_BASE_DOMAIN || "undefined",
|
|
282
300
|
recommendation: "Use server actions for server-side cookie access"
|
|
283
301
|
};
|
|
284
302
|
}
|
|
285
303
|
return {
|
|
286
304
|
hostname: window.location.hostname,
|
|
287
|
-
|
|
305
|
+
cookieDomain: this.COOKIE_DOMAIN || "current domain",
|
|
288
306
|
environment: process.env.NODE_ENV || "unknown",
|
|
289
|
-
protocol: window.location.protocol
|
|
307
|
+
protocol: window.location.protocol,
|
|
308
|
+
sameSite: "lax"
|
|
290
309
|
};
|
|
291
310
|
}
|
|
292
311
|
};
|
|
293
|
-
// Domain configuration
|
|
312
|
+
// Domain configuration - computed once
|
|
294
313
|
_CookieUtils.COOKIE_DOMAIN = process.env.NODE_ENV === "production" ? _CookieUtils.getRootDomain() : void 0;
|
|
295
314
|
var CookieUtils = _CookieUtils;
|
|
296
315
|
|
|
@@ -644,6 +663,9 @@ var BaseMiddlewareHandler = class {
|
|
|
644
663
|
return NextResponse.next();
|
|
645
664
|
}
|
|
646
665
|
const currentUrl = new URL(context.request.url);
|
|
666
|
+
currentUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.LOGIN_REQUIRED);
|
|
667
|
+
currentUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.AUTH_CHECKED);
|
|
668
|
+
currentUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.REDIRECT_URL);
|
|
647
669
|
currentUrl.searchParams.set(MiddlewareConfig.QUERY_PARAMS.LOGIN_REQUIRED, MiddlewareConfig.QUERY_VALUES.LOGIN_REQUIRED);
|
|
648
670
|
currentUrl.searchParams.set(MiddlewareConfig.QUERY_PARAMS.AUTH_CHECKED, MiddlewareConfig.QUERY_VALUES.AUTH_CHECKED);
|
|
649
671
|
currentUrl.searchParams.set(MiddlewareConfig.QUERY_PARAMS.REDIRECT_URL, context.pathname);
|
|
@@ -681,7 +703,7 @@ var BaseMiddlewareHandler = class {
|
|
|
681
703
|
cleanUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.LOGIN_REQUIRED);
|
|
682
704
|
cleanUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.AUTH_CHECKED);
|
|
683
705
|
cleanUrl.searchParams.delete(MiddlewareConfig.QUERY_PARAMS.REDIRECT_URL);
|
|
684
|
-
return NextResponse.redirect(cleanUrl);
|
|
706
|
+
return NextResponse.redirect(cleanUrl, { status: 302 });
|
|
685
707
|
}
|
|
686
708
|
/**
|
|
687
709
|
* Check if URL has auth-related query parameters that need cleanup
|
|
@@ -734,7 +756,8 @@ var AuthenticationHandler = class extends BaseMiddlewareHandler {
|
|
|
734
756
|
if (!this.isDashboardSubdomain(hostname)) {
|
|
735
757
|
return this.continue();
|
|
736
758
|
}
|
|
737
|
-
|
|
759
|
+
const hasAuthCookies = this.hasAuthenticationCookies(cookies);
|
|
760
|
+
if (!hasAuthCookies) {
|
|
738
761
|
return this.addLoginModalParams(context);
|
|
739
762
|
}
|
|
740
763
|
try {
|
|
@@ -749,7 +772,7 @@ var AuthenticationHandler = class extends BaseMiddlewareHandler {
|
|
|
749
772
|
return this.allow();
|
|
750
773
|
} catch (error) {
|
|
751
774
|
console.log("JWT validation failed:", error instanceof Error ? error.message : "Unknown error");
|
|
752
|
-
return this.
|
|
775
|
+
return this.continue();
|
|
753
776
|
}
|
|
754
777
|
}
|
|
755
778
|
};
|
|
@@ -13,12 +13,18 @@ var _CookieUtils = class _CookieUtils {
|
|
|
13
13
|
static getRefreshTokenKey() {
|
|
14
14
|
return process.env.AUTH_REFRESH_TOKEN_KEY || "auth_refresh_token";
|
|
15
15
|
}
|
|
16
|
-
// Use current domain in development
|
|
17
16
|
/**
|
|
18
17
|
* Get root domain for subdomain support
|
|
18
|
+
* Must match the domain used by backend when setting cookies
|
|
19
19
|
*/
|
|
20
20
|
static getRootDomain() {
|
|
21
|
-
if (typeof window === "undefined")
|
|
21
|
+
if (typeof window === "undefined") {
|
|
22
|
+
const baseDomain = process.env.NEXT_PUBLIC_BASE_DOMAIN;
|
|
23
|
+
if (baseDomain && process.env.NODE_ENV === "production") {
|
|
24
|
+
return `.${baseDomain}`;
|
|
25
|
+
}
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
22
28
|
const hostname = window.location.hostname;
|
|
23
29
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
24
30
|
return void 0;
|
|
@@ -32,13 +38,15 @@ var _CookieUtils = class _CookieUtils {
|
|
|
32
38
|
}
|
|
33
39
|
return void 0;
|
|
34
40
|
}
|
|
41
|
+
// Use current domain in development
|
|
35
42
|
/**
|
|
36
43
|
* Get common cookie options
|
|
37
44
|
*/
|
|
38
45
|
static getCookieOptions() {
|
|
39
46
|
return {
|
|
40
47
|
path: "/",
|
|
41
|
-
sameSite: "
|
|
48
|
+
sameSite: "lax",
|
|
49
|
+
// Changed from 'strict' to 'lax' for cross-subdomain
|
|
42
50
|
secure: process.env.NODE_ENV === "production",
|
|
43
51
|
// Only secure in production
|
|
44
52
|
domain: this.COOKIE_DOMAIN
|
|
@@ -128,18 +136,26 @@ var _CookieUtils = class _CookieUtils {
|
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
138
|
* Clear all authentication cookies (client-side only)
|
|
139
|
+
* Clears cookies from both current domain and root domain
|
|
131
140
|
*/
|
|
132
141
|
static clearAuthCookies() {
|
|
133
142
|
if (this.isServerSide()) {
|
|
134
143
|
console.warn("clearAuthCookies called on server side - use server actions instead");
|
|
135
144
|
return;
|
|
136
145
|
}
|
|
137
|
-
const
|
|
146
|
+
const accessKey = this.getAccessTokenKey();
|
|
147
|
+
const refreshKey = this.getRefreshTokenKey();
|
|
148
|
+
const rootDomainOptions = {
|
|
138
149
|
path: "/",
|
|
139
150
|
domain: this.COOKIE_DOMAIN
|
|
140
151
|
};
|
|
141
|
-
_jscookie2.default.remove(
|
|
142
|
-
_jscookie2.default.remove(
|
|
152
|
+
_jscookie2.default.remove(accessKey, rootDomainOptions);
|
|
153
|
+
_jscookie2.default.remove(refreshKey, rootDomainOptions);
|
|
154
|
+
const currentDomainOptions = {
|
|
155
|
+
path: "/"
|
|
156
|
+
};
|
|
157
|
+
_jscookie2.default.remove(accessKey, currentDomainOptions);
|
|
158
|
+
_jscookie2.default.remove(refreshKey, currentDomainOptions);
|
|
143
159
|
}
|
|
144
160
|
/**
|
|
145
161
|
* Check if cookies are supported/enabled (client-side only)
|
|
@@ -206,18 +222,21 @@ var _CookieUtils = class _CookieUtils {
|
|
|
206
222
|
return {
|
|
207
223
|
error: "Server-side rendering - no domain info available",
|
|
208
224
|
environment: process.env.NODE_ENV || "unknown",
|
|
225
|
+
cookieDomain: this.COOKIE_DOMAIN || "undefined",
|
|
226
|
+
baseDomain: process.env.NEXT_PUBLIC_BASE_DOMAIN || "undefined",
|
|
209
227
|
recommendation: "Use server actions for server-side cookie access"
|
|
210
228
|
};
|
|
211
229
|
}
|
|
212
230
|
return {
|
|
213
231
|
hostname: window.location.hostname,
|
|
214
|
-
|
|
232
|
+
cookieDomain: this.COOKIE_DOMAIN || "current domain",
|
|
215
233
|
environment: process.env.NODE_ENV || "unknown",
|
|
216
|
-
protocol: window.location.protocol
|
|
234
|
+
protocol: window.location.protocol,
|
|
235
|
+
sameSite: "lax"
|
|
217
236
|
};
|
|
218
237
|
}
|
|
219
238
|
};
|
|
220
|
-
// Domain configuration
|
|
239
|
+
// Domain configuration - computed once
|
|
221
240
|
_CookieUtils.COOKIE_DOMAIN = process.env.NODE_ENV === "production" ? _CookieUtils.getRootDomain() : void 0;
|
|
222
241
|
var CookieUtils = _CookieUtils;
|
|
223
242
|
|
|
@@ -13,12 +13,18 @@ var _CookieUtils = class _CookieUtils {
|
|
|
13
13
|
static getRefreshTokenKey() {
|
|
14
14
|
return process.env.AUTH_REFRESH_TOKEN_KEY || "auth_refresh_token";
|
|
15
15
|
}
|
|
16
|
-
// Use current domain in development
|
|
17
16
|
/**
|
|
18
17
|
* Get root domain for subdomain support
|
|
18
|
+
* Must match the domain used by backend when setting cookies
|
|
19
19
|
*/
|
|
20
20
|
static getRootDomain() {
|
|
21
|
-
if (typeof window === "undefined")
|
|
21
|
+
if (typeof window === "undefined") {
|
|
22
|
+
const baseDomain = process.env.NEXT_PUBLIC_BASE_DOMAIN;
|
|
23
|
+
if (baseDomain && process.env.NODE_ENV === "production") {
|
|
24
|
+
return `.${baseDomain}`;
|
|
25
|
+
}
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
22
28
|
const hostname = window.location.hostname;
|
|
23
29
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
24
30
|
return void 0;
|
|
@@ -32,13 +38,15 @@ var _CookieUtils = class _CookieUtils {
|
|
|
32
38
|
}
|
|
33
39
|
return void 0;
|
|
34
40
|
}
|
|
41
|
+
// Use current domain in development
|
|
35
42
|
/**
|
|
36
43
|
* Get common cookie options
|
|
37
44
|
*/
|
|
38
45
|
static getCookieOptions() {
|
|
39
46
|
return {
|
|
40
47
|
path: "/",
|
|
41
|
-
sameSite: "
|
|
48
|
+
sameSite: "lax",
|
|
49
|
+
// Changed from 'strict' to 'lax' for cross-subdomain
|
|
42
50
|
secure: process.env.NODE_ENV === "production",
|
|
43
51
|
// Only secure in production
|
|
44
52
|
domain: this.COOKIE_DOMAIN
|
|
@@ -128,18 +136,26 @@ var _CookieUtils = class _CookieUtils {
|
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
138
|
* Clear all authentication cookies (client-side only)
|
|
139
|
+
* Clears cookies from both current domain and root domain
|
|
131
140
|
*/
|
|
132
141
|
static clearAuthCookies() {
|
|
133
142
|
if (this.isServerSide()) {
|
|
134
143
|
console.warn("clearAuthCookies called on server side - use server actions instead");
|
|
135
144
|
return;
|
|
136
145
|
}
|
|
137
|
-
const
|
|
146
|
+
const accessKey = this.getAccessTokenKey();
|
|
147
|
+
const refreshKey = this.getRefreshTokenKey();
|
|
148
|
+
const rootDomainOptions = {
|
|
138
149
|
path: "/",
|
|
139
150
|
domain: this.COOKIE_DOMAIN
|
|
140
151
|
};
|
|
141
|
-
Cookies.remove(
|
|
142
|
-
Cookies.remove(
|
|
152
|
+
Cookies.remove(accessKey, rootDomainOptions);
|
|
153
|
+
Cookies.remove(refreshKey, rootDomainOptions);
|
|
154
|
+
const currentDomainOptions = {
|
|
155
|
+
path: "/"
|
|
156
|
+
};
|
|
157
|
+
Cookies.remove(accessKey, currentDomainOptions);
|
|
158
|
+
Cookies.remove(refreshKey, currentDomainOptions);
|
|
143
159
|
}
|
|
144
160
|
/**
|
|
145
161
|
* Check if cookies are supported/enabled (client-side only)
|
|
@@ -206,18 +222,21 @@ var _CookieUtils = class _CookieUtils {
|
|
|
206
222
|
return {
|
|
207
223
|
error: "Server-side rendering - no domain info available",
|
|
208
224
|
environment: process.env.NODE_ENV || "unknown",
|
|
225
|
+
cookieDomain: this.COOKIE_DOMAIN || "undefined",
|
|
226
|
+
baseDomain: process.env.NEXT_PUBLIC_BASE_DOMAIN || "undefined",
|
|
209
227
|
recommendation: "Use server actions for server-side cookie access"
|
|
210
228
|
};
|
|
211
229
|
}
|
|
212
230
|
return {
|
|
213
231
|
hostname: window.location.hostname,
|
|
214
|
-
|
|
232
|
+
cookieDomain: this.COOKIE_DOMAIN || "current domain",
|
|
215
233
|
environment: process.env.NODE_ENV || "unknown",
|
|
216
|
-
protocol: window.location.protocol
|
|
234
|
+
protocol: window.location.protocol,
|
|
235
|
+
sameSite: "lax"
|
|
217
236
|
};
|
|
218
237
|
}
|
|
219
238
|
};
|
|
220
|
-
// Domain configuration
|
|
239
|
+
// Domain configuration - computed once
|
|
221
240
|
_CookieUtils.COOKIE_DOMAIN = process.env.NODE_ENV === "production" ? _CookieUtils.getRootDomain() : void 0;
|
|
222
241
|
var CookieUtils = _CookieUtils;
|
|
223
242
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailsentry-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Next.js 15 authentication package with multi-step auth flow, cross-tab sync, and Zustand state management",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -38,21 +38,6 @@
|
|
|
38
38
|
"README.md",
|
|
39
39
|
"ZUSTAND_MIGRATION.md"
|
|
40
40
|
],
|
|
41
|
-
"scripts": {
|
|
42
|
-
"dev": "next dev --turbopack",
|
|
43
|
-
"build": "next build",
|
|
44
|
-
"build:package": "tsup",
|
|
45
|
-
"build:package:watch": "tsup --watch",
|
|
46
|
-
"build:link": "npm run build:package && npm link",
|
|
47
|
-
"link:sample": "cd ../nextjs-sample && npm link mailsentry-auth",
|
|
48
|
-
"build:link:sample": "npm run build:link && npm run link:sample",
|
|
49
|
-
"link:cutly": "cd ../cutly && pnpm link ../auth-nextjs",
|
|
50
|
-
"build:link:cutly": "pnpm run build:package && pnpm run link:cutly",
|
|
51
|
-
"start": "next start",
|
|
52
|
-
"lint": "next lint",
|
|
53
|
-
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,scss}\"",
|
|
54
|
-
"prepublishOnly": "npm run build:package"
|
|
55
|
-
},
|
|
56
41
|
"peerDependencies": {
|
|
57
42
|
"next": ">=15.0.0",
|
|
58
43
|
"react": ">=18.0.0 || >=19.0.0",
|
|
@@ -99,5 +84,22 @@
|
|
|
99
84
|
"url": "https://github.com/danielaei/mailsentry-auth.git"
|
|
100
85
|
},
|
|
101
86
|
"author": "danielaei",
|
|
102
|
-
"license": "MIT"
|
|
103
|
-
|
|
87
|
+
"license": "MIT",
|
|
88
|
+
"scripts": {
|
|
89
|
+
"dev": "next dev --turbopack",
|
|
90
|
+
"build": "next build",
|
|
91
|
+
"build:package": "tsup",
|
|
92
|
+
"build:package:watch": "tsup --watch",
|
|
93
|
+
"build:link": "npm run build:package && npm link",
|
|
94
|
+
"link:sample": "cd ../nextjs-sample && npm link mailsentry-auth",
|
|
95
|
+
"build:link:sample": "npm run build:link && npm run link:sample",
|
|
96
|
+
"link:cutly": "cd ../cutly && pnpm link ../auth-nextjs",
|
|
97
|
+
"build:link:cutly": "pnpm run build:package && pnpm run link:cutly",
|
|
98
|
+
"start": "next start",
|
|
99
|
+
"lint": "next lint",
|
|
100
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,scss}\"",
|
|
101
|
+
"publish:patch": "bash scripts/publish-package.sh patch",
|
|
102
|
+
"publish:minor": "bash scripts/publish-package.sh minor",
|
|
103
|
+
"publish:major": "bash scripts/publish-package.sh major"
|
|
104
|
+
}
|
|
105
|
+
}
|