@jskit-ai/auth-web 0.2.47 → 0.2.49
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 +2 -0
- package/fixtures/sign-in/main.js +2 -0
- package/package.json +2 -2
- package/src/client/composables/loginView/useLoginViewActions.js +4 -0
- package/src/client/composables/loginView/useLoginViewState.js +22 -5
- package/src/client/composables/useDefaultSignOutView.js +6 -2
- package/src/client/runtime/useLoginView.js +9 -3
- package/src/client/views/DefaultLoginView.vue +9 -1
- package/test/defaultSignOutView.test.js +105 -0
- package/test/loginViewActions.test.js +7 -1
- package/test/loginViewState.test.js +33 -0
- package/test/secondFactor.browser.test.js +7 -3
- package/test/signIn.browser.test.js +44 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `DefaultLoginView` takes `fallbackReturnTo` (default `/`, so an app that does not set it is unchanged): where a sign-in lands when the address names no `returnTo`, or one refused as on another origin or as `/auth/login` or `/auth/signout`, and the fallback of the main-screen link and of a provider's callback. An app whose `/` is not its app, such as a static website its server serves, names its landing there. Sign-out without a `returnTo` now opens sign-in without one (it sent `?returnTo=/`), so that landing applies after it; a sign-out with a `returnTo` still passes it on.
|
|
6
|
+
- A browser the shell found signed in at boot no longer sees the sign-in form for the moment the page takes to check the session again and send it on: the card is not rendered while the boot session says signed in, and appears if that check finds the session gone. A confirmation link or a provider's callback still shows its own state, and a signed-out visitor sees the form at once. The card is also hidden while a session started elsewhere sends the page on.
|
|
5
7
|
- Up to medium width, the account control's name begins with the initials its avatar shows: "AN ana.ferreira" for ana.ferreira without a picture, the person's name alone with one. That round button is named by its aria-label, and WCAG 2.5.3 Label in Name asks that a control's name hold the text it shows, the words a person using speech input says to press it (axe `label-content-name-mismatch`). Its avatar is hidden from assistive technology (`aria-hidden="true"`), since the name says whose account it is; hiding it alone, as 0.2.45 did, left the finding, as axe counts every word drawn on the screen. On wider windows the control's name is the text it shows, as before.
|
|
6
8
|
- Email change over HTTP: `POST /api/email-change` (signed in, `{ email, password }`) asks for it and `POST /api/email-change/confirm` (public, `{ token }`) uses the link, each limited per address by `config.auth.rateLimits.emailChange` (5 a minute) and `emailChangeConfirm` (10 a minute). The page the link opens is `DefaultEmailChangeView` (`./client/views/DefaultEmailChangeView`, route component `auth-email-change`, the `auth.email-change` route at `/auth/email-change`, public, registered by an application's own page as the sign-in, reset and sign-out pages are): it confirms the link once, takes the token out of the address, and says the new email or why the link was refused (`jskit.auth.emailChange.*`).
|
|
7
9
|
- `POST /api/login/pass` hands `signInWithPass` the request that posted the pass, so local auth keeps the session's address and browser.
|
package/fixtures/sign-in/main.js
CHANGED
|
@@ -129,6 +129,8 @@ const router = createRouter({
|
|
|
129
129
|
{ path: "/auth/login", component: DefaultLoginView },
|
|
130
130
|
{ path: "/auth/reset-password", component: DefaultResetPasswordView },
|
|
131
131
|
{ path: "/auth/signout", component: DefaultSignOutView },
|
|
132
|
+
// An app whose "/" is not its app names where a sign-in lands.
|
|
133
|
+
{ path: "/auth/landing/login", component: { render: () => h(DefaultLoginView, { fallbackReturnTo: "/home?landed=app" }) } },
|
|
132
134
|
{ path: "/auth/branded/login", component: branded(DefaultLoginView) },
|
|
133
135
|
{ path: "/auth/branded/reset-password", component: branded(DefaultResetPasswordView) },
|
|
134
136
|
{ path: "/auth/branded/signout", component: branded(DefaultSignOutView) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.49",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@jskit-ai/auth-core": "0.2.31",
|
|
37
37
|
"@jskit-ai/http-runtime": "0.2.27",
|
|
38
38
|
"@jskit-ai/kernel": "0.2.27",
|
|
39
|
-
"@jskit-ai/shell-web": "0.2.
|
|
39
|
+
"@jskit-ai/shell-web": "0.2.42",
|
|
40
40
|
"@tanstack/vue-query": "^5.90.5",
|
|
41
41
|
"pinia": "^4.0.3",
|
|
42
42
|
"vue": "^3.5.44",
|
|
@@ -556,8 +556,11 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
|
|
|
556
556
|
const callbackHandled = await handleOAuthCallbackIfPresent();
|
|
557
557
|
if (!callbackHandled && session?.authenticated) {
|
|
558
558
|
replacePage(state.requestedReturnTo.value);
|
|
559
|
+
return;
|
|
559
560
|
}
|
|
561
|
+
state.redirectingSignedIn.value = false;
|
|
560
562
|
} catch (error) {
|
|
563
|
+
state.redirectingSignedIn.value = false;
|
|
561
564
|
setErrorMessage(serverMessage(error, t("jskit.auth.login.error.initializeFailed")));
|
|
562
565
|
} finally {
|
|
563
566
|
state.loading.value = false;
|
|
@@ -573,6 +576,7 @@ export function useLoginViewActions({ state, validation, queryClient, errorRunti
|
|
|
573
576
|
try {
|
|
574
577
|
const session = await refreshSession();
|
|
575
578
|
if (session?.authenticated) {
|
|
579
|
+
state.redirectingSignedIn.value = true;
|
|
576
580
|
replacePage(state.requestedReturnTo.value);
|
|
577
581
|
}
|
|
578
582
|
} catch {
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
SUBMIT_LABEL_BY_MODE
|
|
18
18
|
} from "./constants.js";
|
|
19
19
|
import { normalizeEmailAddress, maskEmail } from "./identityHelpers.js";
|
|
20
|
+
import { CONFIRMATION_TOKEN_PARAM } from "./confirmationLink.js";
|
|
21
|
+
import { readOAuthCallbackParamsFromUrl } from "../../runtime/oauthCallbackRuntime.js";
|
|
20
22
|
import { pageLocation } from "../../browser.js";
|
|
21
23
|
import { useJskitText } from "../../i18n.js";
|
|
22
24
|
import {
|
|
@@ -37,8 +39,15 @@ function resolveInitialMode() {
|
|
|
37
39
|
return LOGIN_MODE;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @param {{
|
|
44
|
+
* placementContext: import("vue").Ref<Record<string, any> | null>,
|
|
45
|
+
* fallbackReturnTo?: string,
|
|
46
|
+
* signedIn?: boolean
|
|
47
|
+
* }} options `fallbackReturnTo` is where a sign-in lands without a usable returnTo; `signedIn` is the session the
|
|
48
|
+
* shell read at boot.
|
|
49
|
+
*/
|
|
50
|
+
export function useLoginViewState({ placementContext, fallbackReturnTo = "/", signedIn = false }) {
|
|
42
51
|
const { t } = useJskitText();
|
|
43
52
|
const mode = ref(resolveInitialMode());
|
|
44
53
|
const email = ref(normalizeEmailAddress(readWindowSearchParam("email")));
|
|
@@ -75,6 +84,13 @@ export function useLoginViewState({ placementContext }) {
|
|
|
75
84
|
// The code of the confirmation link this page was opened with, confirmed with the password typed next to it.
|
|
76
85
|
const confirmationLinkToken = ref("");
|
|
77
86
|
const invitationToken = ref(readWindowSearchParam("invitationToken") || readWindowSearchParam("inviteToken"));
|
|
87
|
+
// A browser the shell found signed in is sent on, so it is shown no form meanwhile; a confirmation link or a
|
|
88
|
+
// sign-in callback shows its own state.
|
|
89
|
+
const redirectingSignedIn = ref(
|
|
90
|
+
signedIn === true &&
|
|
91
|
+
!readWindowSearchParam(CONFIRMATION_TOKEN_PARAM) &&
|
|
92
|
+
!readOAuthCallbackParamsFromUrl(pageLocation()?.href)
|
|
93
|
+
);
|
|
78
94
|
|
|
79
95
|
const isLogin = computed(() => mode.value === LOGIN_MODE);
|
|
80
96
|
const isRegister = computed(() => mode.value === REGISTER_MODE);
|
|
@@ -127,17 +143,17 @@ export function useLoginViewState({ placementContext }) {
|
|
|
127
143
|
resolveAllowedOriginsFromPlacementContext(placementContext.value)
|
|
128
144
|
);
|
|
129
145
|
const requestedReturnTo = ref(
|
|
130
|
-
normalizeAuthReturnToPath(readWindowSearchParam("returnTo"),
|
|
146
|
+
normalizeAuthReturnToPath(readWindowSearchParam("returnTo"), fallbackReturnTo, {
|
|
131
147
|
allowedOrigins: allowedReturnToOrigins.value
|
|
132
148
|
})
|
|
133
149
|
);
|
|
134
150
|
const mainScreenPath = computed(() => {
|
|
135
|
-
const normalizedReturnTo = normalizeAuthReturnToPath(requestedReturnTo.value,
|
|
151
|
+
const normalizedReturnTo = normalizeAuthReturnToPath(requestedReturnTo.value, fallbackReturnTo, {
|
|
136
152
|
allowedOrigins: allowedReturnToOrigins.value
|
|
137
153
|
});
|
|
138
154
|
const surfaceId = resolveSurfaceIdFromPlacementPathname(placementContext.value, normalizedReturnTo);
|
|
139
155
|
const rootPath = resolveSurfaceRootPathFromPlacementContext(placementContext.value, surfaceId || "");
|
|
140
|
-
return normalizeAuthReturnToPath(rootPath,
|
|
156
|
+
return normalizeAuthReturnToPath(rootPath, fallbackReturnTo, {
|
|
141
157
|
allowedOrigins: allowedReturnToOrigins.value
|
|
142
158
|
});
|
|
143
159
|
});
|
|
@@ -330,6 +346,7 @@ export function useLoginViewState({ placementContext }) {
|
|
|
330
346
|
confirmationCode,
|
|
331
347
|
confirmationLinkToken,
|
|
332
348
|
invitationToken,
|
|
349
|
+
redirectingSignedIn,
|
|
333
350
|
isLogin,
|
|
334
351
|
isRegister,
|
|
335
352
|
isForgot,
|
|
@@ -12,7 +12,7 @@ import { useJskitText } from "../i18n.js";
|
|
|
12
12
|
|
|
13
13
|
function readReturnToPathFromLocation({ allowedOrigins = [] } = {}) {
|
|
14
14
|
const params = new URLSearchParams(window.location.search || "");
|
|
15
|
-
return normalizeAuthReturnToPath(params.get("returnTo"), "
|
|
15
|
+
return normalizeAuthReturnToPath(params.get("returnTo"), "", {
|
|
16
16
|
allowedOrigins
|
|
17
17
|
});
|
|
18
18
|
}
|
|
@@ -32,7 +32,8 @@ export function useDefaultSignOutView() {
|
|
|
32
32
|
const errorRuntime = useShellWebErrorRuntime();
|
|
33
33
|
const status = ref("pending");
|
|
34
34
|
const errorMessage = ref("");
|
|
35
|
-
|
|
35
|
+
// "" sends the browser to sign-in without a returnTo, where the sign-in's own landing applies.
|
|
36
|
+
const returnToPath = ref("");
|
|
36
37
|
const allowedReturnToOrigins = computed(() =>
|
|
37
38
|
resolveAllowedOriginsFromPlacementContext(placementContext.value)
|
|
38
39
|
);
|
|
@@ -59,6 +60,9 @@ export function useDefaultSignOutView() {
|
|
|
59
60
|
path: "/auth/login",
|
|
60
61
|
surfaceId: "auth"
|
|
61
62
|
});
|
|
63
|
+
if (!returnToPath.value) {
|
|
64
|
+
return loginTarget.href;
|
|
65
|
+
}
|
|
62
66
|
const params = new URLSearchParams({
|
|
63
67
|
returnTo: returnToPath.value
|
|
64
68
|
});
|
|
@@ -2,18 +2,23 @@ import { onMounted } from "vue";
|
|
|
2
2
|
import { useQueryClient } from "@tanstack/vue-query";
|
|
3
3
|
import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
|
|
4
4
|
import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
|
|
5
|
-
import { useAuthOAuthLaunchClient } from "./inject.js";
|
|
5
|
+
import { useAuthGuardRuntime, useAuthOAuthLaunchClient } from "./inject.js";
|
|
6
6
|
import { useLoginViewState } from "../composables/loginView/useLoginViewState.js";
|
|
7
7
|
import { useLoginViewValidation } from "../composables/loginView/useLoginViewValidation.js";
|
|
8
8
|
import { useLoginViewActions } from "../composables/loginView/useLoginViewActions.js";
|
|
9
9
|
import { useSessionRecheckOnShow } from "../composables/loginView/useSessionRecheckOnShow.js";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** @param {{ fallbackReturnTo?: string }} [options] where a sign-in lands without a usable returnTo */
|
|
12
|
+
function useLoginView({ fallbackReturnTo = "/" } = {}) {
|
|
12
13
|
const { context: placementContext } = useWebPlacementContext();
|
|
13
14
|
const queryClient = useQueryClient();
|
|
14
15
|
const errorRuntime = useShellWebErrorRuntime();
|
|
15
16
|
|
|
16
|
-
const state = useLoginViewState({
|
|
17
|
+
const state = useLoginViewState({
|
|
18
|
+
placementContext,
|
|
19
|
+
fallbackReturnTo,
|
|
20
|
+
signedIn: useAuthGuardRuntime().getState()?.authenticated === true
|
|
21
|
+
});
|
|
17
22
|
const validation = useLoginViewValidation({ state });
|
|
18
23
|
const actions = useLoginViewActions({
|
|
19
24
|
state,
|
|
@@ -34,6 +39,7 @@ function useLoginView() {
|
|
|
34
39
|
isLogin: state.isLogin,
|
|
35
40
|
isRegister: state.isRegister,
|
|
36
41
|
isEmailConfirmationPending: state.isEmailConfirmationPending,
|
|
42
|
+
redirectingSignedIn: state.redirectingSignedIn,
|
|
37
43
|
canUsePasswordLogin: state.canUsePasswordLogin,
|
|
38
44
|
canRegister: state.canRegister,
|
|
39
45
|
canRequestPasswordRecovery: state.canRequestPasswordRecovery,
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
<template v-if="$slots.brand" #brand="brand">
|
|
4
4
|
<slot name="brand" v-bind="brand" />
|
|
5
5
|
</template>
|
|
6
|
+
<!-- A browser the shell found signed in is on its way to the page it asked for: it is shown no form. -->
|
|
6
7
|
<v-card
|
|
8
|
+
v-if="!redirectingSignedIn"
|
|
7
9
|
class="auth-card"
|
|
8
10
|
:class="{ 'auth-card--mobile': isMobileViewport }"
|
|
9
11
|
variant="flat"
|
|
@@ -330,6 +332,11 @@ import AuthScreen from "./AuthScreen.vue";
|
|
|
330
332
|
import { useLoginView } from "../runtime/useLoginView.js";
|
|
331
333
|
import { useJskitText } from "../i18n.js";
|
|
332
334
|
|
|
335
|
+
const props = defineProps({
|
|
336
|
+
// Where a sign-in lands when the address names no returnTo, or one refused as foreign or as a sign-in loop.
|
|
337
|
+
fallbackReturnTo: { type: String, default: "/" }
|
|
338
|
+
});
|
|
339
|
+
|
|
333
340
|
const { mobile: isMobileViewport } = useDisplay({ mobileBreakpoint: 960 });
|
|
334
341
|
const { t } = useJskitText();
|
|
335
342
|
|
|
@@ -341,6 +348,7 @@ const {
|
|
|
341
348
|
isLogin,
|
|
342
349
|
isRegister,
|
|
343
350
|
isEmailConfirmationPending,
|
|
351
|
+
redirectingSignedIn,
|
|
344
352
|
canUsePasswordLogin,
|
|
345
353
|
canRegister,
|
|
346
354
|
canRequestPasswordRecovery,
|
|
@@ -390,7 +398,7 @@ const {
|
|
|
390
398
|
oauthProviderIcon,
|
|
391
399
|
startOAuthSignIn,
|
|
392
400
|
oauthProviderButtonLabel
|
|
393
|
-
} = useLoginView();
|
|
401
|
+
} = useLoginView({ fallbackReturnTo: props.fallbackReturnTo });
|
|
394
402
|
|
|
395
403
|
function togglePasswordVisibility() {
|
|
396
404
|
showPassword.value = !showPassword.value;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createRenderer, defineComponent } from "vue";
|
|
4
|
+
import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "@jskit-ai/shell-web/client/placement";
|
|
5
|
+
import { useDefaultSignOutView } from "../src/client/composables/useDefaultSignOutView.js";
|
|
6
|
+
import { AUTH_GUARD_RUNTIME_INJECTION_KEY } from "../src/client/runtime/inject.js";
|
|
7
|
+
import { clearAuthCsrfTokenCache } from "../src/client/runtime/authHttpClient.js";
|
|
8
|
+
|
|
9
|
+
function node(type) {
|
|
10
|
+
return { type, children: [], parent: null };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const renderer = createRenderer({
|
|
14
|
+
createElement: node,
|
|
15
|
+
createText: () => node("text"),
|
|
16
|
+
createComment: () => node("comment"),
|
|
17
|
+
setText() {},
|
|
18
|
+
setElementText() {},
|
|
19
|
+
patchProp() {},
|
|
20
|
+
parentNode: (item) => item.parent,
|
|
21
|
+
nextSibling: () => null,
|
|
22
|
+
insert(item, parent) {
|
|
23
|
+
item.parent = parent;
|
|
24
|
+
parent.children.push(item);
|
|
25
|
+
},
|
|
26
|
+
remove(item) {
|
|
27
|
+
item.parent?.children.splice(item.parent.children.indexOf(item), 1);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function createJsonResponse(payload = {}) {
|
|
32
|
+
return {
|
|
33
|
+
ok: true,
|
|
34
|
+
status: 200,
|
|
35
|
+
headers: {
|
|
36
|
+
get: (name) => (String(name || "").toLowerCase() === "content-type" ? "application/json" : null)
|
|
37
|
+
},
|
|
38
|
+
json: async () => payload,
|
|
39
|
+
text: async () => JSON.stringify(payload)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const PLACEMENT_CONTEXT = Object.freeze({
|
|
44
|
+
surfaceConfig: {
|
|
45
|
+
tenancyMode: "none",
|
|
46
|
+
defaultSurfaceId: "home",
|
|
47
|
+
enabledSurfaceIds: ["home", "auth"],
|
|
48
|
+
surfacesById: {
|
|
49
|
+
home: { id: "home", enabled: true, pagesRoot: "home", routeBase: "/home", requiresWorkspace: false },
|
|
50
|
+
auth: { id: "auth", enabled: true, pagesRoot: "auth", routeBase: "/auth", requiresWorkspace: false }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Signs out on the page `/auth/signout${search}` and gives the address the browser is sent to.
|
|
56
|
+
async function signOutAt(t, search) {
|
|
57
|
+
const originalWindow = globalThis.window;
|
|
58
|
+
const destinations = [];
|
|
59
|
+
globalThis.window = {
|
|
60
|
+
location: {
|
|
61
|
+
href: `https://example.com/auth/signout${search}`,
|
|
62
|
+
origin: "https://example.com",
|
|
63
|
+
search,
|
|
64
|
+
replace: (path) => destinations.push(path),
|
|
65
|
+
assign: (path) => destinations.push(path)
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
t.after(() => {
|
|
69
|
+
if (originalWindow === undefined) delete globalThis.window;
|
|
70
|
+
else globalThis.window = originalWindow;
|
|
71
|
+
clearAuthCsrfTokenCache();
|
|
72
|
+
});
|
|
73
|
+
t.mock.method(globalThis, "fetch", async () => createJsonResponse({ ok: true, authenticated: false, csrfToken: "csrf" }));
|
|
74
|
+
|
|
75
|
+
const app = renderer.createApp(
|
|
76
|
+
defineComponent({
|
|
77
|
+
setup() {
|
|
78
|
+
useDefaultSignOutView();
|
|
79
|
+
return () => null;
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
app.provide(AUTH_GUARD_RUNTIME_INJECTION_KEY, { refresh: async () => ({ authenticated: false }) });
|
|
84
|
+
app.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, {
|
|
85
|
+
getContext: () => PLACEMENT_CONTEXT,
|
|
86
|
+
setContext: () => PLACEMENT_CONTEXT,
|
|
87
|
+
getPlacements: () => [],
|
|
88
|
+
getRevision: () => 0,
|
|
89
|
+
subscribe: () => () => {}
|
|
90
|
+
});
|
|
91
|
+
app.mount(node("root"));
|
|
92
|
+
t.after(() => app.unmount());
|
|
93
|
+
for (let turn = 0; turn < 50 && destinations.length === 0; turn += 1) {
|
|
94
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
95
|
+
}
|
|
96
|
+
return destinations;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
test("a sign-out without a returnTo opens sign-in without one, so the sign-in's own landing applies", async (t) => {
|
|
100
|
+
assert.deepEqual(await signOutAt(t, ""), ["/auth/login"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a sign-out with a returnTo passes it on to sign-in", async (t) => {
|
|
104
|
+
assert.deepEqual(await signOutAt(t, "?returnTo=%2Fhome"), ["/auth/login?returnTo=%2Fhome"]);
|
|
105
|
+
});
|
|
@@ -29,6 +29,7 @@ function createMinimalLoginViewState(requestedReturnTo = "/") {
|
|
|
29
29
|
errorMessage: { value: "" },
|
|
30
30
|
infoMessage: { value: "" },
|
|
31
31
|
loading: { value: false },
|
|
32
|
+
redirectingSignedIn: { value: false },
|
|
32
33
|
submitAttempted: { value: false },
|
|
33
34
|
email: { value: "" },
|
|
34
35
|
password: { value: "password-123" },
|
|
@@ -62,8 +63,10 @@ function createMinimalLoginViewState(requestedReturnTo = "/") {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
for (const authenticated of [true, false]) {
|
|
65
|
-
test(`login initialization ${authenticated ? "redirects an existing session" : "
|
|
66
|
+
test(`login initialization ${authenticated ? "redirects an existing session, showing no form" : "shows the form once the boot session has ended"}`, async (t) => {
|
|
66
67
|
const state = createMinimalLoginViewState("/w/acme/bookings?date=2026-09-16");
|
|
68
|
+
// The shell read a signed-in session at boot, so the page renders no form while it checks again.
|
|
69
|
+
state.redirectingSignedIn.value = true;
|
|
67
70
|
const destinations = [];
|
|
68
71
|
const originalWindow = globalThis.window;
|
|
69
72
|
globalThis.window = {
|
|
@@ -94,6 +97,7 @@ for (const authenticated of [true, false]) {
|
|
|
94
97
|
|
|
95
98
|
assert.equal(fetch.mock.callCount(), 1);
|
|
96
99
|
assert.deepEqual(destinations, authenticated ? [state.requestedReturnTo.value] : []);
|
|
100
|
+
assert.equal(state.redirectingSignedIn.value, authenticated);
|
|
97
101
|
assert.equal(state.loading.value, false);
|
|
98
102
|
assert.equal(state.errorMessage.value, "");
|
|
99
103
|
});
|
|
@@ -134,6 +138,7 @@ test("an open sign-in page forwards once a session starts elsewhere", async (t)
|
|
|
134
138
|
await actions.redirectIfSignedIn();
|
|
135
139
|
await actions.redirectIfSignedIn();
|
|
136
140
|
assert.deepEqual(destinations, [], "a signed-out or offline check keeps the form");
|
|
141
|
+
assert.equal(state.redirectingSignedIn.value, false);
|
|
137
142
|
|
|
138
143
|
state.loading.value = true;
|
|
139
144
|
await actions.redirectIfSignedIn();
|
|
@@ -142,6 +147,7 @@ test("an open sign-in page forwards once a session starts elsewhere", async (t)
|
|
|
142
147
|
state.loading.value = false;
|
|
143
148
|
await actions.redirectIfSignedIn();
|
|
144
149
|
assert.deepEqual(destinations, [state.requestedReturnTo.value]);
|
|
150
|
+
assert.equal(state.redirectingSignedIn.value, true, "the form hides while the page is sent on");
|
|
145
151
|
assert.equal(state.errorMessage.value, "");
|
|
146
152
|
});
|
|
147
153
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import { useLoginViewState } from "../src/client/composables/loginView/useLoginViewState.js";
|
|
5
|
+
|
|
6
|
+
// The sign-in page's state for the address `search`, with no surfaces placed.
|
|
7
|
+
function stateAt(t, search, options = {}) {
|
|
8
|
+
const originalWindow = globalThis.window;
|
|
9
|
+
globalThis.window = { location: { href: `https://example.com/auth/login${search}`, origin: "https://example.com", search } };
|
|
10
|
+
t.after(() => {
|
|
11
|
+
if (originalWindow === undefined) delete globalThis.window;
|
|
12
|
+
else globalThis.window = originalWindow;
|
|
13
|
+
});
|
|
14
|
+
return useLoginViewState({ placementContext: ref(null), ...options });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test("a sign-in with no usable returnTo lands where the app names, and on / when it names nothing", (t) => {
|
|
18
|
+
assert.equal(stateAt(t, "").requestedReturnTo.value, "/");
|
|
19
|
+
for (const search of ["", "?returnTo=https://elsewhere.example/steal", "?returnTo=/auth/login", "?returnTo=/auth/signout"]) {
|
|
20
|
+
assert.equal(stateAt(t, search, { fallbackReturnTo: "/account" }).requestedReturnTo.value, "/account", search);
|
|
21
|
+
}
|
|
22
|
+
assert.equal(
|
|
23
|
+
stateAt(t, "?returnTo=/console/projects", { fallbackReturnTo: "/account" }).requestedReturnTo.value,
|
|
24
|
+
"/console/projects"
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a browser the shell found signed in is shown no form, unless it opened a confirmation link or a callback", (t) => {
|
|
29
|
+
assert.equal(stateAt(t, "?returnTo=/home").redirectingSignedIn.value, false);
|
|
30
|
+
assert.equal(stateAt(t, "?returnTo=/home", { signedIn: true }).redirectingSignedIn.value, true);
|
|
31
|
+
assert.equal(stateAt(t, "?confirmation_token=abc", { signedIn: true }).redirectingSignedIn.value, false);
|
|
32
|
+
assert.equal(stateAt(t, "?code=abc&state=xyz&provider=google", { signedIn: true }).redirectingSignedIn.value, false);
|
|
33
|
+
});
|
|
@@ -191,10 +191,14 @@ test("removing the authenticator takes a code or a recovery code, shows a wait b
|
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
// Whether every part of the shell's page around the console (its app bar and main at least) is inert, as it is while
|
|
194
|
-
// the step-up dialog is open, or else every part live.
|
|
194
|
+
// the step-up dialog is open, or else every part live but a closed modal drawer or side sheet, which stays inert.
|
|
195
195
|
async function shellPageIs(page, inert) {
|
|
196
|
-
const parts = await page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) =>
|
|
197
|
-
|
|
196
|
+
const parts = await page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) => ({
|
|
197
|
+
inert: part.inert,
|
|
198
|
+
closedDrawer: part.classList.contains("v-navigation-drawer--temporary") &&
|
|
199
|
+
!part.classList.contains("v-navigation-drawer--active")
|
|
200
|
+
})));
|
|
201
|
+
return parts.length >= 2 && parts.every((part) => part.inert === (inert || part.closedDrawer));
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
test("a route that asks for a fresh code opens the step-up dialog over an inert page, runs again after the code, and Escape cancels it, focus returning to the control each time", options, async () => {
|
|
@@ -56,13 +56,16 @@ async function openApp({ session = SIGNED_OUT, routes = {}, viewport = { width:
|
|
|
56
56
|
const page = await browser.newPage({ baseURL: runtime.baseURL, viewport });
|
|
57
57
|
page.setDefaultTimeout(15_000);
|
|
58
58
|
page.setDefaultNavigationTimeout(60_000);
|
|
59
|
-
|
|
59
|
+
// `holdSession`, a promise, holds every session read after the first (the shell's, at boot) until it settles.
|
|
60
|
+
const api = { session, routes, requests: [], unexpected: [], errors: [], page, sessionReads: 0, holdSession: null };
|
|
60
61
|
page.on("pageerror", (error) => api.errors.push(error.message));
|
|
61
62
|
await page.route("**/api/**", async (route) => {
|
|
62
63
|
const request = route.request();
|
|
63
64
|
const { pathname, search } = new URL(request.url());
|
|
64
65
|
const key = `${request.method()} ${pathname}`;
|
|
65
66
|
if (key === "GET /api/session") {
|
|
67
|
+
api.sessionReads += 1;
|
|
68
|
+
if (api.sessionReads > 1 && api.holdSession) await api.holdSession;
|
|
66
69
|
await route.fulfill({ json: api.session });
|
|
67
70
|
return;
|
|
68
71
|
}
|
|
@@ -208,6 +211,46 @@ test("a signed-in visitor leaves the sign-in page, on opening it and when a sess
|
|
|
208
211
|
await finish(api);
|
|
209
212
|
});
|
|
210
213
|
|
|
214
|
+
test("a browser the shell found signed in is shown no form while sign-in checks again, and the form if its session ended", options, async () => {
|
|
215
|
+
const api = await openApp({ session: SIGNED_IN });
|
|
216
|
+
const { page } = api;
|
|
217
|
+
let releaseSession;
|
|
218
|
+
api.holdSession = new Promise((resolve) => { releaseSession = resolve; });
|
|
219
|
+
await page.goto("/auth/login?returnTo=/home");
|
|
220
|
+
await expect.poll(() => api.sessionReads).toBe(2);
|
|
221
|
+
await expect(page.locator(".login-screen")).toBeVisible();
|
|
222
|
+
await expect(page.locator(".login-screen form, .login-screen input, .login-screen button")).toHaveCount(0);
|
|
223
|
+
|
|
224
|
+
api.session = SIGNED_OUT;
|
|
225
|
+
releaseSession();
|
|
226
|
+
await expect(page.getByTestId("auth-submit")).toBeVisible();
|
|
227
|
+
await expect(page.getByLabel("Email")).toBeVisible();
|
|
228
|
+
assert.equal(new URL(page.url()).pathname, "/auth/login");
|
|
229
|
+
await finish(api);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("a sign-in with no usable returnTo lands on the page the app names", options, async () => {
|
|
233
|
+
const api = await openApp({
|
|
234
|
+
routes: {
|
|
235
|
+
"POST /api/login": () => {
|
|
236
|
+
api.session = SIGNED_IN;
|
|
237
|
+
return { json: { ok: true, username: "Ada Lovelace" } };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const { page } = api;
|
|
242
|
+
await page.goto("/auth/landing/login?returnTo=https://elsewhere.example/steal");
|
|
243
|
+
await signIn(page, "ada@example.com", "correct horse");
|
|
244
|
+
await waitForHome(page);
|
|
245
|
+
assert.equal(new URL(page.url()).search, "?landed=app");
|
|
246
|
+
|
|
247
|
+
// Signed in now: opening sign-in with no returnTo sends the browser to the same landing.
|
|
248
|
+
await page.goto("/auth/landing/login");
|
|
249
|
+
await waitForHome(page);
|
|
250
|
+
assert.equal(new URL(page.url()).search, "?landed=app");
|
|
251
|
+
await finish(api);
|
|
252
|
+
});
|
|
253
|
+
|
|
211
254
|
test("the shell guard sends a signed-out visitor to sign-in, and follows the session", options, async () => {
|
|
212
255
|
const api = await openApp();
|
|
213
256
|
const { page } = api;
|