auth-vir 5.0.1 → 5.0.3
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.
|
@@ -265,17 +265,22 @@ export class BackendAuthClient {
|
|
|
265
265
|
}
|
|
266
266
|
/** Use these headers to log out the user. */
|
|
267
267
|
async createLogoutHeaders(params) {
|
|
268
|
+
const clearingAllCookies = !!params.allCookies;
|
|
268
269
|
const signUpCookieHeaders = params.allCookies || params.isSignUpCookie
|
|
269
270
|
? generateLogoutHeaders(await this.getCookieParams({
|
|
270
271
|
isSignUpCookie: true,
|
|
271
272
|
requestHeaders: undefined,
|
|
272
|
-
})
|
|
273
|
+
}), {
|
|
274
|
+
preserveCsrf: !clearingAllCookies,
|
|
275
|
+
})
|
|
273
276
|
: undefined;
|
|
274
277
|
const authCookieHeaders = params.allCookies || !params.isSignUpCookie
|
|
275
278
|
? generateLogoutHeaders(await this.getCookieParams({
|
|
276
279
|
isSignUpCookie: false,
|
|
277
280
|
requestHeaders: undefined,
|
|
278
|
-
})
|
|
281
|
+
}), {
|
|
282
|
+
preserveCsrf: !clearingAllCookies,
|
|
283
|
+
})
|
|
279
284
|
: undefined;
|
|
280
285
|
return {
|
|
281
286
|
'set-cookie': mergeHeaderValues(signUpCookieHeaders?.['set-cookie'], authCookieHeaders?.['set-cookie']),
|
package/dist/auth.d.ts
CHANGED
|
@@ -71,4 +71,11 @@ sessionStartedAt?: number | undefined): Promise<Record<string, string[]>>;
|
|
|
71
71
|
export declare function generateLogoutHeaders(cookieConfig: Readonly<SelectFrom<CookieParams, {
|
|
72
72
|
hostOrigin: true;
|
|
73
73
|
isDev: true;
|
|
74
|
-
}
|
|
74
|
+
}>>, options?: Readonly<{
|
|
75
|
+
/**
|
|
76
|
+
* When `true`, the CSRF cookie is preserved (not cleared). Use this when clearing only one
|
|
77
|
+
* cookie type (e.g., the auth cookie) while keeping the other active session (e.g.,
|
|
78
|
+
* sign-up) that still needs its CSRF token.
|
|
79
|
+
*/
|
|
80
|
+
preserveCsrf?: boolean | undefined;
|
|
81
|
+
}>): Record<string, string[]>;
|
package/dist/auth.js
CHANGED
|
@@ -118,11 +118,15 @@ sessionStartedAt) {
|
|
|
118
118
|
*
|
|
119
119
|
* @category Auth : Host
|
|
120
120
|
*/
|
|
121
|
-
export function generateLogoutHeaders(cookieConfig) {
|
|
121
|
+
export function generateLogoutHeaders(cookieConfig, options) {
|
|
122
122
|
return {
|
|
123
123
|
'set-cookie': [
|
|
124
124
|
clearAuthCookie(cookieConfig),
|
|
125
|
-
|
|
125
|
+
...(options?.preserveCsrf
|
|
126
|
+
? []
|
|
127
|
+
: [
|
|
128
|
+
clearCsrfCookie(cookieConfig),
|
|
129
|
+
]),
|
|
126
130
|
],
|
|
127
131
|
};
|
|
128
132
|
}
|
package/package.json
CHANGED
|
@@ -578,6 +578,8 @@ export class BackendAuthClient<
|
|
|
578
578
|
'set-cookie': string[];
|
|
579
579
|
}
|
|
580
580
|
> {
|
|
581
|
+
const clearingAllCookies = !!params.allCookies;
|
|
582
|
+
|
|
581
583
|
const signUpCookieHeaders =
|
|
582
584
|
params.allCookies || params.isSignUpCookie
|
|
583
585
|
? generateLogoutHeaders(
|
|
@@ -585,6 +587,9 @@ export class BackendAuthClient<
|
|
|
585
587
|
isSignUpCookie: true,
|
|
586
588
|
requestHeaders: undefined,
|
|
587
589
|
}),
|
|
590
|
+
{
|
|
591
|
+
preserveCsrf: !clearingAllCookies,
|
|
592
|
+
},
|
|
588
593
|
)
|
|
589
594
|
: undefined;
|
|
590
595
|
const authCookieHeaders =
|
|
@@ -594,6 +599,9 @@ export class BackendAuthClient<
|
|
|
594
599
|
isSignUpCookie: false,
|
|
595
600
|
requestHeaders: undefined,
|
|
596
601
|
}),
|
|
602
|
+
{
|
|
603
|
+
preserveCsrf: !clearingAllCookies,
|
|
604
|
+
},
|
|
597
605
|
)
|
|
598
606
|
: undefined;
|
|
599
607
|
|
package/src/auth.ts
CHANGED
|
@@ -189,11 +189,23 @@ export async function generateSuccessfulLoginHeaders(
|
|
|
189
189
|
*/
|
|
190
190
|
export function generateLogoutHeaders(
|
|
191
191
|
cookieConfig: Readonly<SelectFrom<CookieParams, {hostOrigin: true; isDev: true}>>,
|
|
192
|
+
options?: Readonly<{
|
|
193
|
+
/**
|
|
194
|
+
* When `true`, the CSRF cookie is preserved (not cleared). Use this when clearing only one
|
|
195
|
+
* cookie type (e.g., the auth cookie) while keeping the other active session (e.g.,
|
|
196
|
+
* sign-up) that still needs its CSRF token.
|
|
197
|
+
*/
|
|
198
|
+
preserveCsrf?: boolean | undefined;
|
|
199
|
+
}>,
|
|
192
200
|
): Record<string, string[]> {
|
|
193
201
|
return {
|
|
194
202
|
'set-cookie': [
|
|
195
203
|
clearAuthCookie(cookieConfig),
|
|
196
|
-
|
|
204
|
+
...(options?.preserveCsrf
|
|
205
|
+
? []
|
|
206
|
+
: [
|
|
207
|
+
clearCsrfCookie(cookieConfig),
|
|
208
|
+
]),
|
|
197
209
|
],
|
|
198
210
|
};
|
|
199
211
|
}
|