@snokam/auth 6.3.10 → 6.3.11
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/CHANGELOG.md +6 -0
- package/package.json +5 -5
- package/src/hooks.ts +2 -6
- package/src/session/confirm.test.ts +35 -0
- package/src/session/confirm.ts +16 -0
- package/src/session/confirmed.tsx +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.3.11](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.3.10...%40snokam%2Fauth%406.3.11) (2026-11-13)
|
|
7
|
+
|
|
8
|
+
### Performance Improvements
|
|
9
|
+
|
|
10
|
+
- **tasks:** the task page loads without waiting for the review queue ([#3689](https://github.com/snokam/components/issues/3689)) ([afadbbe](https://github.com/snokam/components/commit/afadbbefc94ac8e81a3971be522ad93e2a2bba74))
|
|
11
|
+
|
|
6
12
|
## [6.3.10](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.3.9...%40snokam%2Fauth%406.3.10) (2026-11-13)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @snokam/auth
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snokam/auth",
|
|
3
3
|
"description": "Snøkam auth components",
|
|
4
|
-
"version": "6.3.
|
|
4
|
+
"version": "6.3.11",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"types": "src/index.ts",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"@mui/material": "^9.5.0",
|
|
27
27
|
"next-auth": "4.24.15",
|
|
28
28
|
"path-to-regexp": "^9.0.0",
|
|
29
|
-
"@snokam/api-client": "1.0.0",
|
|
30
|
-
"@snokam/identity": "1.1.1",
|
|
31
29
|
"@snokam/page-content": "6.12.8",
|
|
32
|
-
"@snokam/
|
|
30
|
+
"@snokam/api-client": "1.0.0",
|
|
33
31
|
"@snokam/tenant": "4.5.7",
|
|
34
|
-
"@snokam/ui": "7.11.0"
|
|
32
|
+
"@snokam/ui": "7.11.0",
|
|
33
|
+
"@snokam/react-query": "1.1.3",
|
|
34
|
+
"@snokam/identity": "1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"next": "16.4.5",
|
package/src/hooks.ts
CHANGED
|
@@ -7,11 +7,7 @@ import { leaveEndedSession } from "./impersonation/ended";
|
|
|
7
7
|
import { useOwnIdentity } from "./identity/own";
|
|
8
8
|
import { useSession } from "./session/useSession";
|
|
9
9
|
import { isReusable, type CachedToken } from "./token/reuse";
|
|
10
|
-
import {
|
|
11
|
-
confirmSessionState,
|
|
12
|
-
fetchSessionFromServer,
|
|
13
|
-
withRetries,
|
|
14
|
-
} from "./session/confirm";
|
|
10
|
+
import { confirmServerSession, withRetries } from "./session/confirm";
|
|
15
11
|
import {
|
|
16
12
|
ConsentRequiredError,
|
|
17
13
|
failureOf,
|
|
@@ -112,7 +108,7 @@ export function fetchOwnToken(): Promise<string> {
|
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
async function signInAgainIfSignedOut(error: SignedOutError): Promise<void> {
|
|
115
|
-
const state = await
|
|
111
|
+
const state = await confirmServerSession();
|
|
116
112
|
if (state !== "signed-out") throw error;
|
|
117
113
|
const here = `${window.location.pathname}${window.location.search}`;
|
|
118
114
|
window.location.href = `/auth/login?callbackUrl=${encodeURIComponent(here)}`;
|
|
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
|
|
3
3
|
import {
|
|
4
4
|
confirmSessionState,
|
|
5
5
|
readSessionState,
|
|
6
|
+
sharedConfirmation,
|
|
6
7
|
withRetries,
|
|
7
8
|
} from "./confirm.ts";
|
|
8
9
|
|
|
@@ -98,3 +99,37 @@ test("errors that are not transient are not retried", async () => {
|
|
|
98
99
|
);
|
|
99
100
|
assert.equal(attempts, 1);
|
|
100
101
|
});
|
|
102
|
+
|
|
103
|
+
test("callers asking at the same time share one session check", async () => {
|
|
104
|
+
let checks = 0;
|
|
105
|
+
let answer: (state: "signed-in") => void = () => {};
|
|
106
|
+
const confirm = sharedConfirmation(() => {
|
|
107
|
+
checks += 1;
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
answer = resolve;
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const first = confirm();
|
|
114
|
+
const second = confirm();
|
|
115
|
+
answer("signed-in");
|
|
116
|
+
|
|
117
|
+
assert.deepEqual(await Promise.all([first, second]), [
|
|
118
|
+
"signed-in",
|
|
119
|
+
"signed-in",
|
|
120
|
+
]);
|
|
121
|
+
assert.equal(checks, 1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a later caller gets a fresh session check", async () => {
|
|
125
|
+
let checks = 0;
|
|
126
|
+
const confirm = sharedConfirmation(async () => {
|
|
127
|
+
checks += 1;
|
|
128
|
+
return "signed-in";
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
await confirm();
|
|
132
|
+
await confirm();
|
|
133
|
+
|
|
134
|
+
assert.equal(checks, 2);
|
|
135
|
+
});
|
package/src/session/confirm.ts
CHANGED
|
@@ -61,3 +61,19 @@ export async function confirmSessionState(
|
|
|
61
61
|
|
|
62
62
|
export const fetchSessionFromServer = () =>
|
|
63
63
|
fetch("/api/auth/session", { credentials: "include", cache: "no-store" });
|
|
64
|
+
|
|
65
|
+
export function sharedConfirmation(
|
|
66
|
+
confirm: () => Promise<SessionState>
|
|
67
|
+
): () => Promise<SessionState> {
|
|
68
|
+
let pending: Promise<SessionState> | null = null;
|
|
69
|
+
return () => {
|
|
70
|
+
pending ??= confirm().finally(() => {
|
|
71
|
+
pending = null;
|
|
72
|
+
});
|
|
73
|
+
return pending;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const confirmServerSession = sharedConfirmation(() =>
|
|
78
|
+
confirmSessionState(fetchSessionFromServer)
|
|
79
|
+
);
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type SessionContextValue,
|
|
7
7
|
} from "next-auth/react";
|
|
8
8
|
import type { Session } from "next-auth";
|
|
9
|
-
import {
|
|
9
|
+
import { confirmServerSession } from "./confirm";
|
|
10
10
|
import { holdSession } from "./hold";
|
|
11
11
|
|
|
12
12
|
export const ConfirmedSessionContext =
|
|
@@ -32,7 +32,7 @@ export function ConfirmedSessionProvider({
|
|
|
32
32
|
if (status !== "unauthenticated" || !lastSignedIn || confirmedSignedOut)
|
|
33
33
|
return;
|
|
34
34
|
let cancelled = false;
|
|
35
|
-
|
|
35
|
+
confirmServerSession().then((state) => {
|
|
36
36
|
if (!cancelled && state === "signed-out") setConfirmedSignedOut(true);
|
|
37
37
|
});
|
|
38
38
|
return () => {
|