@jskit-ai/auth-web 0.2.5 → 0.2.7
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/fixtures/sign-in/index.html +12 -0
- package/fixtures/sign-in/main.js +97 -0
- package/fixtures/sign-in/vite.config.mjs +9 -0
- package/locales/en.json +0 -1
- package/package.json +10 -5
- package/src/client/browser.js +37 -0
- package/src/client/composables/loginView/oauthCallbackUrl.js +7 -4
- package/src/client/composables/loginView/rememberedAccountStorage.js +6 -4
- package/src/client/composables/loginView/useLoginViewActions.js +19 -24
- package/src/client/composables/loginView/useLoginViewState.js +10 -18
- package/src/client/composables/loginView/useLoginViewValidation.js +2 -1
- package/src/client/composables/loginView/useSessionRecheckOnShow.js +5 -2
- package/src/client/composables/useDefaultResetPasswordView.js +109 -0
- package/src/client/composables/useDefaultSignOutView.js +2 -10
- package/src/client/providers/AuthWebClientProvider.js +20 -2
- package/src/client/runtime/authClient.js +67 -33
- package/src/client/runtime/authGuardRuntime.js +51 -99
- package/src/client/runtime/inject.js +38 -30
- package/src/client/runtime/oauthCallbackRuntime.js +8 -12
- package/src/client/runtime/oauthLaunchClient.js +18 -23
- package/src/client/runtime/passwordRecoveryCallbackRuntime.js +5 -3
- package/src/client/runtime/popupOAuthLaunchClient.js +70 -59
- package/src/client/runtime/useLoginView.js +7 -4
- package/src/client/runtime/useSignOut.js +51 -42
- package/src/client/stores/useAuthStore.js +13 -17
- package/src/client/types.js +86 -0
- package/src/client/views/AuthProfileMenuLinkItem.vue +2 -4
- package/src/client/views/DefaultLoginView.vue +4 -36
- package/src/client/views/DefaultResetPasswordView.vue +15 -97
- package/src/test/playwright.js +6 -3
- package/test/clientSurface.test.js +2 -2
- package/test/loginViewActions.test.js +1 -0
- package/test/playwright.test.js +44 -1
- package/test/popupOAuthLaunchClient.test.js +2 -2
- package/test/provider.test.js +4 -2
- package/test/signIn.browser.test.js +365 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Sign-in regression</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/main.js"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createPinia } from "pinia";
|
|
3
|
+
import { createRouter, createWebHistory, RouterView } from "vue-router";
|
|
4
|
+
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
|
5
|
+
import "vuetify/styles";
|
|
6
|
+
import { createVuetify } from "vuetify";
|
|
7
|
+
import * as components from "vuetify/components";
|
|
8
|
+
import * as directives from "vuetify/directives";
|
|
9
|
+
import { aliases, mdi } from "vuetify/iconsets/mdi-svg";
|
|
10
|
+
import { SHELL_WEB_ERROR_RUNTIME_KEY } from "@jskit-ai/shell-web/client/error";
|
|
11
|
+
import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "@jskit-ai/shell-web/client/placement";
|
|
12
|
+
import AuthProfileWidget from "../../src/client/views/AuthProfileWidget.vue";
|
|
13
|
+
import DefaultLoginView from "../../src/client/views/DefaultLoginView.vue";
|
|
14
|
+
import DefaultResetPasswordView from "../../src/client/views/DefaultResetPasswordView.vue";
|
|
15
|
+
import DefaultSignOutView from "../../src/client/views/DefaultSignOutView.vue";
|
|
16
|
+
import { AuthWebClientProvider } from "../../src/client/providers/AuthWebClientProvider.js";
|
|
17
|
+
import { useAuthStore } from "../../src/client/stores/useAuthStore.js";
|
|
18
|
+
|
|
19
|
+
// The shell's two runtimes as doubles; the auth client above them is the real one the provider builds.
|
|
20
|
+
window.authFixture = { reports: [], bootstrapRefreshes: [], context: {} };
|
|
21
|
+
|
|
22
|
+
let context = {
|
|
23
|
+
surfaceConfig: {
|
|
24
|
+
tenancyMode: "none",
|
|
25
|
+
defaultSurfaceId: "home",
|
|
26
|
+
enabledSurfaceIds: ["home", "auth"],
|
|
27
|
+
surfacesById: {
|
|
28
|
+
home: { id: "home", enabled: true, pagesRoot: "home", routeBase: "/home", requiresWorkspace: false },
|
|
29
|
+
auth: { id: "auth", enabled: true, pagesRoot: "auth", routeBase: "/auth", requiresWorkspace: false }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const placement = {
|
|
34
|
+
getContext: () => context,
|
|
35
|
+
getPlacements: () => [],
|
|
36
|
+
getRevision: () => 0,
|
|
37
|
+
subscribe: () => () => {},
|
|
38
|
+
setContext(patch) {
|
|
39
|
+
context = { ...context, ...patch };
|
|
40
|
+
window.authFixture.context = patch;
|
|
41
|
+
return context;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const errorRuntime = {
|
|
45
|
+
report(event) {
|
|
46
|
+
window.authFixture.reports.push(event);
|
|
47
|
+
return { skipped: false };
|
|
48
|
+
},
|
|
49
|
+
dismiss: () => 0
|
|
50
|
+
};
|
|
51
|
+
const shell = {
|
|
52
|
+
placement,
|
|
53
|
+
bootstrap: {
|
|
54
|
+
async refresh(reason) {
|
|
55
|
+
window.authFixture.bootstrapRefreshes.push(reason);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const HomePage = {
|
|
61
|
+
setup() {
|
|
62
|
+
const auth = useAuthStore();
|
|
63
|
+
return () => h("div", [
|
|
64
|
+
h("p", { "data-testid": "home" }, `Signed in: ${auth.authenticated}`),
|
|
65
|
+
h(AuthProfileWidget)
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const router = createRouter({
|
|
70
|
+
history: createWebHistory(),
|
|
71
|
+
routes: [
|
|
72
|
+
{ path: "/home", component: HomePage },
|
|
73
|
+
{ path: "/auth/login", component: DefaultLoginView },
|
|
74
|
+
{ path: "/auth/reset-password", component: DefaultResetPasswordView },
|
|
75
|
+
{ path: "/auth/signout", component: DefaultSignOutView }
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
const app = createApp({ render: () => h(components.VApp, null, { default: () => h(components.VMain, null, { default: () => h(RouterView) }) }) });
|
|
79
|
+
const pinia = createPinia();
|
|
80
|
+
app.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, placement);
|
|
81
|
+
app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, errorRuntime);
|
|
82
|
+
app.use(pinia);
|
|
83
|
+
app.use(router);
|
|
84
|
+
app.use(VueQueryPlugin, { queryClient: new QueryClient({ defaultOptions: { queries: { retry: false } } }) });
|
|
85
|
+
app.use(createVuetify({ components, directives, icons: { defaultSet: "mdi", aliases, sets: { mdi } } }));
|
|
86
|
+
// The kernel hands an absent optional capability to a provider as null.
|
|
87
|
+
const outputs = AuthWebClientProvider.setup({
|
|
88
|
+
components: { register() {} },
|
|
89
|
+
mobile: null,
|
|
90
|
+
pinia,
|
|
91
|
+
realtime: null,
|
|
92
|
+
shell,
|
|
93
|
+
vueApp: app
|
|
94
|
+
});
|
|
95
|
+
await AuthWebClientProvider.boot({}, { outputs });
|
|
96
|
+
await router.isReady();
|
|
97
|
+
app.mount("#app");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import vue from "@vitejs/plugin-vue";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
root: fileURLToPath(new URL("./", import.meta.url)),
|
|
7
|
+
plugins: [vue()],
|
|
8
|
+
server: { host: "127.0.0.1", strictPort: true }
|
|
9
|
+
});
|
package/locales/en.json
CHANGED
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"oauthProviderInvalid": "OAuth provider id is invalid.",
|
|
79
79
|
"oauthReturnToInvalid": "OAuth return path is invalid.",
|
|
80
80
|
"oauthStartFailed": "Unable to start OAuth sign-in.",
|
|
81
|
-
"oauthLaunchUnavailable": "OAuth launch client is unavailable.",
|
|
82
81
|
"initializeFailed": "Unable to initialize sign in."
|
|
83
82
|
}
|
|
84
83
|
},
|
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.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"./server/managedPreviewIdentity": "./src/server/managedPreviewIdentity.js",
|
|
14
14
|
"./server/types": "./src/server/types.js",
|
|
15
15
|
"./client": "./src/client/index.js",
|
|
16
|
+
"./client/types": "./src/client/types.js",
|
|
16
17
|
"./client/views/DefaultLoginView": "./src/client/views/DefaultLoginView.vue",
|
|
17
18
|
"./client/views/DefaultResetPasswordView": "./src/client/views/DefaultResetPasswordView.vue",
|
|
18
19
|
"./client/views/DefaultSignOutView": "./src/client/views/DefaultSignOutView.vue",
|
|
@@ -27,10 +28,10 @@
|
|
|
27
28
|
"@mdi/js": "^7.4.47"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@jskit-ai/auth-core": "0.2.
|
|
31
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
32
|
-
"@jskit-ai/kernel": "0.2.
|
|
33
|
-
"@jskit-ai/shell-web": "0.2.
|
|
31
|
+
"@jskit-ai/auth-core": "0.2.5",
|
|
32
|
+
"@jskit-ai/http-runtime": "0.2.5",
|
|
33
|
+
"@jskit-ai/kernel": "0.2.5",
|
|
34
|
+
"@jskit-ai/shell-web": "0.2.5",
|
|
34
35
|
"@tanstack/vue-query": "^5.90.5",
|
|
35
36
|
"pinia": "^4.0.3",
|
|
36
37
|
"vue": "^3.5.44",
|
|
@@ -77,6 +78,10 @@
|
|
|
77
78
|
"subpath": "./client",
|
|
78
79
|
"summary": "Exports auth web client provider, default auth views, and route/provider registration surface."
|
|
79
80
|
},
|
|
81
|
+
{
|
|
82
|
+
"subpath": "./client/types",
|
|
83
|
+
"summary": "Types of the guard runtime, the OAuth launch client and the client.auth capability."
|
|
84
|
+
},
|
|
80
85
|
{
|
|
81
86
|
"subpath": "./server",
|
|
82
87
|
"summary": "Exports auth web server providers, controller/service classes, route builders, and HTTP schema modules."
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What auth-web reads from the browser, each probe written once. Outside a browser, as in a test, there is no window
|
|
3
|
+
* and no document.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The page's window; null outside a browser. */
|
|
7
|
+
function pageWindow() {
|
|
8
|
+
return typeof window === "undefined" ? null : window;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The page's document; null outside a browser. */
|
|
12
|
+
function pageDocument() {
|
|
13
|
+
return typeof document === "undefined" ? null : document;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The page's location; null outside a browser. */
|
|
17
|
+
function pageLocation() {
|
|
18
|
+
return pageWindow()?.location || null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Replaces the page with the one at `path`; does nothing outside a browser.
|
|
23
|
+
* @param {string} path
|
|
24
|
+
*/
|
|
25
|
+
function replacePage(path) {
|
|
26
|
+
const location = pageLocation();
|
|
27
|
+
if (location) {
|
|
28
|
+
location.replace(path);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
pageDocument,
|
|
34
|
+
pageLocation,
|
|
35
|
+
pageWindow,
|
|
36
|
+
replacePage
|
|
37
|
+
};
|
|
@@ -3,13 +3,15 @@ import {
|
|
|
3
3
|
OAUTH_QUERY_PARAM_RETURN_TO
|
|
4
4
|
} from "@jskit-ai/auth-core/shared/oauthCallbackParams";
|
|
5
5
|
import { readOAuthCallbackParamsFromUrl } from "../../runtime/oauthCallbackRuntime.js";
|
|
6
|
+
import { pageLocation } from "../../browser.js";
|
|
6
7
|
|
|
7
8
|
function stripOAuthParamsFromLocation() {
|
|
8
|
-
|
|
9
|
+
const location = pageLocation();
|
|
10
|
+
if (!location) {
|
|
9
11
|
return;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
const nextUrl = new URL(
|
|
14
|
+
const nextUrl = new URL(location.href);
|
|
13
15
|
const oauthParamKeys = [
|
|
14
16
|
"code",
|
|
15
17
|
"access_token",
|
|
@@ -46,11 +48,12 @@ function stripOAuthParamsFromLocation() {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
function readOAuthCallbackParamsFromLocation() {
|
|
49
|
-
|
|
51
|
+
const location = pageLocation();
|
|
52
|
+
if (!location) {
|
|
50
53
|
return null;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
return readOAuthCallbackParamsFromUrl(
|
|
56
|
+
return readOAuthCallbackParamsFromUrl(location.href);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
export {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { normalizeEmailAddress, maskEmail } from "./identityHelpers.js";
|
|
2
|
+
import { pageWindow } from "../../browser.js";
|
|
2
3
|
import { useJskitText } from "../../i18n.js";
|
|
3
4
|
|
|
4
5
|
function resolveLocalStorage() {
|
|
5
|
-
|
|
6
|
+
const storage = pageWindow()?.localStorage;
|
|
7
|
+
if (!storage) {
|
|
6
8
|
return null;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
try {
|
|
10
12
|
const probeKey = "__auth_hint_probe__";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
13
|
+
storage.setItem(probeKey, "1");
|
|
14
|
+
storage.removeItem(probeKey);
|
|
15
|
+
return storage;
|
|
14
16
|
} catch {
|
|
15
17
|
return null;
|
|
16
18
|
}
|
|
@@ -17,17 +17,21 @@ import { completeOAuthPopupSignIn } from "../../runtime/popupOAuthLaunchClient.j
|
|
|
17
17
|
import { ensureCommandSectionValid } from "./validationHelpers.js";
|
|
18
18
|
import { resolveRegisterCompletionState } from "./registerCompletion.js";
|
|
19
19
|
import { inactiveSessionMessage } from "../../runtime/inactiveSessionMessage.js";
|
|
20
|
+
import { replacePage } from "../../browser.js";
|
|
20
21
|
import { useJskitText } from "../../i18n.js";
|
|
21
22
|
|
|
22
23
|
const SESSION_QUERY_KEY = Object.freeze(["auth-web", "session"]);
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @param {{
|
|
27
|
+
* state: import("../../types.js").LoginViewState,
|
|
28
|
+
* validation: import("../../types.js").LoginViewValidation,
|
|
29
|
+
* queryClient: import("@jskit-ai/kernel/client/types").ClientQueryClient,
|
|
30
|
+
* errorRuntime: import("../../types.js").AuthErrorRuntime,
|
|
31
|
+
* oauthLaunchClient: import("../../types.js").AuthOAuthLaunchClient
|
|
32
|
+
* }} options
|
|
33
|
+
*/
|
|
34
|
+
export function useLoginViewActions({ state, validation, queryClient, errorRuntime, oauthLaunchClient }) {
|
|
31
35
|
const { serverMessage, t } = useJskitText();
|
|
32
36
|
|
|
33
37
|
function reportAuthFeedback({
|
|
@@ -93,9 +97,7 @@ export function useLoginViewActions({
|
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
function applySessionPayload(payload) {
|
|
96
|
-
|
|
97
|
-
state.applyCapabilities(payload || {});
|
|
98
|
-
}
|
|
100
|
+
state.applyCapabilities(payload || {});
|
|
99
101
|
if (payload?.authCapabilities || payload?.capabilities) {
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
@@ -150,9 +152,7 @@ export function useLoginViewActions({
|
|
|
150
152
|
if (!session?.authenticated) {
|
|
151
153
|
throw new Error(inactiveSessionMessage(session));
|
|
152
154
|
}
|
|
153
|
-
|
|
154
|
-
window.location.replace(state.requestedReturnTo.value);
|
|
155
|
-
}
|
|
155
|
+
replacePage(state.requestedReturnTo.value);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
async function submitRegister({ normalizedEmail, shouldRememberAccount }) {
|
|
@@ -160,7 +160,7 @@ export function useLoginViewActions({
|
|
|
160
160
|
email: normalizedEmail,
|
|
161
161
|
password: String(state.password.value || "")
|
|
162
162
|
};
|
|
163
|
-
const invitationToken = String(state.invitationToken
|
|
163
|
+
const invitationToken = String(state.invitationToken.value || "").trim();
|
|
164
164
|
if (invitationToken) {
|
|
165
165
|
registerPayload.invitation = {
|
|
166
166
|
token: invitationToken,
|
|
@@ -291,9 +291,7 @@ export function useLoginViewActions({
|
|
|
291
291
|
// browser keeps it open, it continues like an ordinary sign-in.
|
|
292
292
|
completeOAuthPopupSignIn();
|
|
293
293
|
stripOAuthParamsFromLocation();
|
|
294
|
-
|
|
295
|
-
window.location.replace(state.requestedReturnTo.value);
|
|
296
|
-
}
|
|
294
|
+
replacePage(state.requestedReturnTo.value);
|
|
297
295
|
} catch (error) {
|
|
298
296
|
setErrorMessage(serverMessage(error, t("jskit.auth.login.error.oauthCompleteFailed")));
|
|
299
297
|
stripOAuthParamsFromLocation();
|
|
@@ -453,9 +451,6 @@ export function useLoginViewActions({
|
|
|
453
451
|
const params = new URLSearchParams(queryPayload);
|
|
454
452
|
const oauthStartPath = buildAuthOauthStartPath(provider);
|
|
455
453
|
try {
|
|
456
|
-
if (!oauthLaunchClient || typeof oauthLaunchClient.open !== "function") {
|
|
457
|
-
throw new Error(t("jskit.auth.login.error.oauthLaunchUnavailable"));
|
|
458
|
-
}
|
|
459
454
|
await oauthLaunchClient.open({
|
|
460
455
|
url: `${oauthStartPath}?${params.toString()}`
|
|
461
456
|
});
|
|
@@ -470,8 +465,8 @@ export function useLoginViewActions({
|
|
|
470
465
|
try {
|
|
471
466
|
const session = await refreshSession();
|
|
472
467
|
const callbackHandled = await handleOAuthCallbackIfPresent();
|
|
473
|
-
if (!callbackHandled && session?.authenticated
|
|
474
|
-
|
|
468
|
+
if (!callbackHandled && session?.authenticated) {
|
|
469
|
+
replacePage(state.requestedReturnTo.value);
|
|
475
470
|
}
|
|
476
471
|
} catch (error) {
|
|
477
472
|
setErrorMessage(serverMessage(error, t("jskit.auth.login.error.initializeFailed")));
|
|
@@ -488,8 +483,8 @@ export function useLoginViewActions({
|
|
|
488
483
|
}
|
|
489
484
|
try {
|
|
490
485
|
const session = await refreshSession();
|
|
491
|
-
if (session?.authenticated
|
|
492
|
-
|
|
486
|
+
if (session?.authenticated) {
|
|
487
|
+
replacePage(state.requestedReturnTo.value);
|
|
493
488
|
}
|
|
494
489
|
} catch {
|
|
495
490
|
// Still signed out, or offline: the form stays as it is.
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
SUBMIT_LABEL_BY_MODE
|
|
18
18
|
} from "./constants.js";
|
|
19
19
|
import { normalizeEmailAddress, maskEmail } from "./identityHelpers.js";
|
|
20
|
+
import { pageLocation } from "../../browser.js";
|
|
20
21
|
import { useJskitText } from "../../i18n.js";
|
|
21
22
|
import {
|
|
22
23
|
createRememberedAccountHint,
|
|
@@ -25,10 +26,7 @@ import {
|
|
|
25
26
|
} from "./rememberedAccountStorage.js";
|
|
26
27
|
|
|
27
28
|
function readWindowSearchParam(name = "") {
|
|
28
|
-
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
return String(new URLSearchParams(window.location.search || "").get(name) || "").trim();
|
|
29
|
+
return String(new URLSearchParams(pageLocation()?.search || "").get(name) || "").trim();
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
function resolveInitialMode() {
|
|
@@ -39,7 +37,8 @@ function resolveInitialMode() {
|
|
|
39
37
|
return LOGIN_MODE;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
/** @param {{ placementContext: import("vue").Ref<Record<string, any> | null> }} options */
|
|
41
|
+
export function useLoginViewState({ placementContext }) {
|
|
43
42
|
const { t } = useJskitText();
|
|
44
43
|
const mode = ref(resolveInitialMode());
|
|
45
44
|
const email = ref(normalizeEmailAddress(readWindowSearchParam("email")));
|
|
@@ -107,23 +106,19 @@ export function useLoginViewState({ placementContext } = {}) {
|
|
|
107
106
|
});
|
|
108
107
|
const submitLabel = computed(() => modeText(SUBMIT_LABEL_BY_MODE));
|
|
109
108
|
const allowedReturnToOrigins = computed(() =>
|
|
110
|
-
resolveAllowedOriginsFromPlacementContext(placementContext
|
|
109
|
+
resolveAllowedOriginsFromPlacementContext(placementContext.value)
|
|
111
110
|
);
|
|
112
111
|
const requestedReturnTo = ref(
|
|
113
|
-
normalizeAuthReturnToPath(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
allowedOrigins: allowedReturnToOrigins.value
|
|
118
|
-
}
|
|
119
|
-
)
|
|
112
|
+
normalizeAuthReturnToPath(readWindowSearchParam("returnTo"), "/", {
|
|
113
|
+
allowedOrigins: allowedReturnToOrigins.value
|
|
114
|
+
})
|
|
120
115
|
);
|
|
121
116
|
const mainScreenPath = computed(() => {
|
|
122
117
|
const normalizedReturnTo = normalizeAuthReturnToPath(requestedReturnTo.value, "/", {
|
|
123
118
|
allowedOrigins: allowedReturnToOrigins.value
|
|
124
119
|
});
|
|
125
|
-
const surfaceId = resolveSurfaceIdFromPlacementPathname(placementContext
|
|
126
|
-
const rootPath = resolveSurfaceRootPathFromPlacementContext(placementContext
|
|
120
|
+
const surfaceId = resolveSurfaceIdFromPlacementPathname(placementContext.value, normalizedReturnTo);
|
|
121
|
+
const rootPath = resolveSurfaceRootPathFromPlacementContext(placementContext.value, surfaceId || "");
|
|
127
122
|
return normalizeAuthReturnToPath(rootPath, "/", {
|
|
128
123
|
allowedOrigins: allowedReturnToOrigins.value
|
|
129
124
|
});
|
|
@@ -264,9 +259,6 @@ export function useLoginViewState({ placementContext } = {}) {
|
|
|
264
259
|
}
|
|
265
260
|
|
|
266
261
|
function goToMainScreen() {
|
|
267
|
-
if (typeof window !== "object" || !window.location || typeof window.location.assign !== "function") {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
262
|
window.location.assign(mainScreenPath.value);
|
|
271
263
|
}
|
|
272
264
|
|
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
} from "./validationHelpers.js";
|
|
11
11
|
import { useJskitText } from "../../i18n.js";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** @param {{ state: import("../../types.js").LoginViewState }} options */
|
|
14
|
+
export function useLoginViewValidation({ state }) {
|
|
14
15
|
const { t } = useJskitText();
|
|
15
16
|
|
|
16
17
|
function resolveFieldErrorMessages({
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { onBeforeUnmount, onMounted } from "vue";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Runs recheck whenever the page is shown again: focused, made visible, or restored from the back-forward cache, where
|
|
5
|
+
* nothing mounts again.
|
|
6
|
+
* @param {() => unknown} recheck
|
|
7
|
+
*/
|
|
5
8
|
export function useSessionRecheckOnShow(recheck) {
|
|
6
9
|
function recheckWhenShown() {
|
|
7
10
|
if (document.visibilityState === "visible") {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { computed, onMounted, ref } from "vue";
|
|
2
|
+
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
3
|
+
import { authPasswordResetCommand } from "@jskit-ai/auth-core/shared/commands/authPasswordResetCommand";
|
|
4
|
+
import { authHttpRequest } from "../runtime/authHttpClient.js";
|
|
5
|
+
import {
|
|
6
|
+
readPasswordRecoveryCallbackPayloadFromUrl,
|
|
7
|
+
stripPasswordRecoveryCallbackParamsFromLocation
|
|
8
|
+
} from "../runtime/passwordRecoveryCallbackRuntime.js";
|
|
9
|
+
import {
|
|
10
|
+
validateCommandSection,
|
|
11
|
+
resolveFieldValidationMessage
|
|
12
|
+
} from "./loginView/validationHelpers.js";
|
|
13
|
+
import { useJskitText } from "../i18n.js";
|
|
14
|
+
|
|
15
|
+
/** The password reset page: it exchanges the recovery link on mount, then sets the new password. */
|
|
16
|
+
export function useDefaultResetPasswordView() {
|
|
17
|
+
const { serverMessage, t } = useJskitText();
|
|
18
|
+
const status = ref("checking");
|
|
19
|
+
const loading = ref(false);
|
|
20
|
+
const errorMessage = ref("");
|
|
21
|
+
const password = ref("");
|
|
22
|
+
const confirmPassword = ref("");
|
|
23
|
+
const showPassword = ref(false);
|
|
24
|
+
const showConfirmPassword = ref(false);
|
|
25
|
+
|
|
26
|
+
const resetPasswordPayload = computed(() => ({
|
|
27
|
+
password: password.value
|
|
28
|
+
}));
|
|
29
|
+
const resetPasswordValidation = computed(() =>
|
|
30
|
+
validateCommandSection(authPasswordResetCommand, "body", resetPasswordPayload.value)
|
|
31
|
+
);
|
|
32
|
+
const passwordError = computed(() => {
|
|
33
|
+
if (!password.value) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const message = resolveFieldValidationMessage(resetPasswordValidation.value, "password");
|
|
37
|
+
return message ? [message] : [];
|
|
38
|
+
});
|
|
39
|
+
const confirmPasswordError = computed(() => {
|
|
40
|
+
if (!confirmPassword.value) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return password.value === confirmPassword.value ? [] : [t("jskit.auth.resetPassword.passwordsMustMatch")];
|
|
44
|
+
});
|
|
45
|
+
const canSubmit = computed(() =>
|
|
46
|
+
Boolean(password.value) &&
|
|
47
|
+
resetPasswordValidation.value.ok === true &&
|
|
48
|
+
password.value === confirmPassword.value &&
|
|
49
|
+
loading.value !== true
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
async function exchangeRecoveryToken() {
|
|
53
|
+
const recoveryPayload = readPasswordRecoveryCallbackPayloadFromUrl(window.location.href);
|
|
54
|
+
if (!recoveryPayload) {
|
|
55
|
+
status.value = "ready";
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await authHttpRequest(AUTH_PATHS.PASSWORD_RECOVERY, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: recoveryPayload
|
|
62
|
+
});
|
|
63
|
+
stripPasswordRecoveryCallbackParamsFromLocation();
|
|
64
|
+
status.value = "ready";
|
|
65
|
+
} catch (error) {
|
|
66
|
+
status.value = "error";
|
|
67
|
+
errorMessage.value = serverMessage(error, t("jskit.auth.resetPassword.recoveryInvalid"));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function submitReset() {
|
|
72
|
+
if (!canSubmit.value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
loading.value = true;
|
|
76
|
+
errorMessage.value = "";
|
|
77
|
+
try {
|
|
78
|
+
await authHttpRequest(AUTH_PATHS.PASSWORD_RESET, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
body: {
|
|
81
|
+
password: password.value
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
status.value = "done";
|
|
85
|
+
password.value = "";
|
|
86
|
+
confirmPassword.value = "";
|
|
87
|
+
} catch (error) {
|
|
88
|
+
errorMessage.value = serverMessage(error, t("jskit.auth.resetPassword.updateFailed"));
|
|
89
|
+
} finally {
|
|
90
|
+
loading.value = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onMounted(exchangeRecoveryToken);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
status,
|
|
98
|
+
loading,
|
|
99
|
+
errorMessage,
|
|
100
|
+
password,
|
|
101
|
+
confirmPassword,
|
|
102
|
+
showPassword,
|
|
103
|
+
showConfirmPassword,
|
|
104
|
+
passwordError,
|
|
105
|
+
confirmPasswordError,
|
|
106
|
+
canSubmit,
|
|
107
|
+
submitReset
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -6,14 +6,11 @@ import {
|
|
|
6
6
|
resolveSurfaceNavigationTargetFromPlacementContext
|
|
7
7
|
} from "@jskit-ai/shell-web/client/placement";
|
|
8
8
|
import { performSignOutRequest } from "../runtime/useSignOut.js";
|
|
9
|
-
import {
|
|
9
|
+
import { useRequiredAuthGuardRuntime } from "../runtime/inject.js";
|
|
10
10
|
import { normalizeAuthReturnToPath } from "../lib/returnToPath.js";
|
|
11
11
|
import { useJskitText } from "../i18n.js";
|
|
12
12
|
|
|
13
13
|
function readReturnToPathFromLocation({ allowedOrigins = [] } = {}) {
|
|
14
|
-
if (typeof window !== "object" || !window.location) {
|
|
15
|
-
return "/";
|
|
16
|
-
}
|
|
17
14
|
const params = new URLSearchParams(window.location.search || "");
|
|
18
15
|
return normalizeAuthReturnToPath(params.get("returnTo"), "/", {
|
|
19
16
|
allowedOrigins
|
|
@@ -21,9 +18,6 @@ function readReturnToPathFromLocation({ allowedOrigins = [] } = {}) {
|
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
function navigateToPath(path, { replace = true } = {}) {
|
|
24
|
-
if (typeof window !== "object" || !window.location) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
21
|
if (replace) {
|
|
28
22
|
window.location.replace(path);
|
|
29
23
|
return;
|
|
@@ -33,9 +27,7 @@ function navigateToPath(path, { replace = true } = {}) {
|
|
|
33
27
|
|
|
34
28
|
export function useDefaultSignOutView() {
|
|
35
29
|
const { serverMessage, t } = useJskitText();
|
|
36
|
-
const authGuardRuntime =
|
|
37
|
-
required: true
|
|
38
|
-
});
|
|
30
|
+
const authGuardRuntime = useRequiredAuthGuardRuntime();
|
|
39
31
|
const { context: placementContext } = useWebPlacementContext();
|
|
40
32
|
const errorRuntime = useShellWebErrorRuntime();
|
|
41
33
|
const status = ref("pending");
|
|
@@ -3,7 +3,7 @@ import DefaultLoginView from "../views/DefaultLoginView.vue";
|
|
|
3
3
|
import AuthProfileWidget from "../views/AuthProfileWidget.vue";
|
|
4
4
|
import AuthProfileMenuLinkItem from "../views/AuthProfileMenuLinkItem.vue";
|
|
5
5
|
import { useLoginView } from "../runtime/useLoginView.js";
|
|
6
|
-
import { createAuthClient } from "../runtime/authClient.js";
|
|
6
|
+
import { createAuthClient, NO_AUTH_REALTIME } from "../runtime/authClient.js";
|
|
7
7
|
|
|
8
8
|
const AuthWebClientProvider = defineProvider({
|
|
9
9
|
id: "auth.web.client",
|
|
@@ -20,18 +20,36 @@ const AuthWebClientProvider = defineProvider({
|
|
|
20
20
|
provides: {
|
|
21
21
|
auth: "client.auth"
|
|
22
22
|
},
|
|
23
|
+
/**
|
|
24
|
+
* @param {{
|
|
25
|
+
* components: import("@jskit-ai/kernel/client/types").ClientComponents,
|
|
26
|
+
* mobile: import("../types.js").AuthMobile | null,
|
|
27
|
+
* pinia: import("@jskit-ai/kernel/client/types").ClientPinia,
|
|
28
|
+
* realtime: import("../types.js").AuthRealtime | null,
|
|
29
|
+
* shell: import("../types.js").AuthShell,
|
|
30
|
+
* vueApp: import("@jskit-ai/kernel/client/types").ClientVueApp
|
|
31
|
+
* }} capabilities
|
|
32
|
+
*/
|
|
23
33
|
setup({ components, mobile, pinia, realtime, shell, vueApp }) {
|
|
24
34
|
components.register("auth.login.component", DefaultLoginView);
|
|
25
35
|
components.register("auth.login.useLoginView", useLoginView);
|
|
26
36
|
components.register("auth.web.profile.widget", AuthProfileWidget);
|
|
27
37
|
components.register("auth.web.profile.menu.link-item", AuthProfileMenuLinkItem);
|
|
28
38
|
return {
|
|
29
|
-
auth: createAuthClient({
|
|
39
|
+
auth: createAuthClient({
|
|
40
|
+
mobile,
|
|
41
|
+
pinia,
|
|
42
|
+
realtime: realtime ?? NO_AUTH_REALTIME,
|
|
43
|
+
shell,
|
|
44
|
+
vueApp
|
|
45
|
+
})
|
|
30
46
|
};
|
|
31
47
|
},
|
|
48
|
+
/** @param {unknown} _dependencies @param {{ outputs: { auth: import("../types.js").AuthClient } }} context */
|
|
32
49
|
async boot(_dependencies, { outputs }) {
|
|
33
50
|
await outputs.auth.initialize();
|
|
34
51
|
},
|
|
52
|
+
/** @param {unknown} _dependencies @param {{ outputs: { auth: import("../types.js").AuthClient } }} context */
|
|
35
53
|
shutdown(_dependencies, { outputs }) {
|
|
36
54
|
outputs.auth.dispose();
|
|
37
55
|
}
|