@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createBrowserOAuthLaunchClient } from "./oauthLaunchClient.js";
|
|
2
|
+
import { pageWindow } from "../browser.js";
|
|
2
3
|
import { useJskitText } from "../i18n.js";
|
|
3
4
|
|
|
4
5
|
// A sign-in page refuses to be framed, so a framed app (an editor Preview, an
|
|
@@ -12,10 +13,6 @@ const OAUTH_POPUP_LIFETIME_MS = 10 * 60 * 1000;
|
|
|
12
13
|
const OAUTH_POPUP_BLOCKED_MESSAGE =
|
|
13
14
|
"Your browser blocked the sign-in window. Allow pop-ups for this page, then try again.";
|
|
14
15
|
|
|
15
|
-
function browserWindow() {
|
|
16
|
-
return typeof window === "object" && window ? window : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
16
|
function isFramedWindow(win) {
|
|
20
17
|
try {
|
|
21
18
|
return win.self !== win.top;
|
|
@@ -39,66 +36,80 @@ function popupFeatures(win, width = 520, height = 680) {
|
|
|
39
36
|
return `popup=yes,width=${width},height=${height},left=${left},top=${top}`;
|
|
40
37
|
}
|
|
41
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The channel a sign-in window answers on; a browser without BroadcastChannel gets one that carries nothing.
|
|
41
|
+
* @param {any} win
|
|
42
|
+
*/
|
|
42
43
|
function openChannel(win) {
|
|
43
|
-
|
|
44
|
+
// readable-check: allow method-probe - platform object: an older browser has no BroadcastChannel, so only the opener link answers
|
|
45
|
+
if (typeof win.BroadcastChannel === "function") {
|
|
46
|
+
return new win.BroadcastChannel(OAUTH_POPUP_MESSAGE_TYPE);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
onmessage: null,
|
|
50
|
+
close() {},
|
|
51
|
+
postMessage() {}
|
|
52
|
+
};
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @param {{
|
|
57
|
+
* window?: any,
|
|
58
|
+
* fallback?: import("../types.js").AuthOAuthLaunchClient,
|
|
59
|
+
* onComplete?: () => void
|
|
60
|
+
* }} [options]
|
|
61
|
+
*/
|
|
46
62
|
function createPopupOAuthLaunchClient({
|
|
47
|
-
window: win =
|
|
63
|
+
window: win = pageWindow(),
|
|
48
64
|
fallback = createBrowserOAuthLaunchClient(),
|
|
49
|
-
onComplete =
|
|
65
|
+
onComplete = () => win.location.reload()
|
|
50
66
|
} = {}) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
popup.focus?.();
|
|
67
|
+
async function open({ url = "" } = {}) {
|
|
68
|
+
if (!win || !isFramedWindow(win)) {
|
|
69
|
+
return fallback.open({ url });
|
|
70
|
+
}
|
|
71
|
+
const normalizedUrl = String(url || "").trim();
|
|
72
|
+
if (!normalizedUrl) {
|
|
73
|
+
throw new Error("OAuth launch URL is required.");
|
|
74
|
+
}
|
|
75
|
+
const popup = win.open(normalizedUrl, OAUTH_POPUP_WINDOW_NAME, popupFeatures(win));
|
|
76
|
+
if (!popup) {
|
|
77
|
+
throw new Error(useJskitText().t("jskit.auth.oauth.popupBlocked"));
|
|
78
|
+
}
|
|
79
|
+
storageOf(win)?.setItem(OAUTH_POPUP_MARKER_KEY, String(Date.now()));
|
|
80
|
+
popup.focus();
|
|
66
81
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
if (typeof onComplete === "function") {
|
|
81
|
-
onComplete();
|
|
82
|
-
} else {
|
|
83
|
-
win.location.reload();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const onMessage = (event) => {
|
|
87
|
-
if (event?.origin === win.location.origin && event?.data?.type === OAUTH_POPUP_MESSAGE_TYPE) {
|
|
88
|
-
finish(true);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
win.addEventListener("message", onMessage);
|
|
92
|
-
if (channel) {
|
|
93
|
-
channel.onmessage = (event) => {
|
|
94
|
-
if (event?.data?.type === OAUTH_POPUP_MESSAGE_TYPE) {
|
|
95
|
-
finish(true);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
82
|
+
// Some sign-in pages cut the opener link, so the window also answers on
|
|
83
|
+
// a same-origin channel. Closing it without finishing leaves this page as it was.
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const channel = openChannel(win);
|
|
86
|
+
let timer = null;
|
|
87
|
+
const finish = (completed) => {
|
|
88
|
+
win.removeEventListener("message", onMessage);
|
|
89
|
+
channel.close();
|
|
90
|
+
win.clearTimeout(timer);
|
|
91
|
+
resolve(completed);
|
|
92
|
+
if (completed) {
|
|
93
|
+
onComplete();
|
|
98
94
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
};
|
|
96
|
+
const onMessage = (event) => {
|
|
97
|
+
if (event?.origin === win.location.origin && event?.data?.type === OAUTH_POPUP_MESSAGE_TYPE) {
|
|
98
|
+
finish(true);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
win.addEventListener("message", onMessage);
|
|
102
|
+
channel.onmessage = (event) => {
|
|
103
|
+
if (event?.data?.type === OAUTH_POPUP_MESSAGE_TYPE) {
|
|
104
|
+
finish(true);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
timer = win.setTimeout(() => finish(false), OAUTH_POPUP_LIFETIME_MS);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
open
|
|
102
113
|
});
|
|
103
114
|
}
|
|
104
115
|
|
|
@@ -116,7 +127,7 @@ function sameOriginOpener(win) {
|
|
|
116
127
|
* sign-in window opened by a framed app, it tells that app and closes, and the
|
|
117
128
|
* function returns true. Otherwise it does nothing and returns false.
|
|
118
129
|
*/
|
|
119
|
-
function completeOAuthPopupSignIn(win =
|
|
130
|
+
function completeOAuthPopupSignIn(win = pageWindow()) {
|
|
120
131
|
if (!win) {
|
|
121
132
|
return false;
|
|
122
133
|
}
|
|
@@ -131,8 +142,8 @@ function completeOAuthPopupSignIn(win = browserWindow()) {
|
|
|
131
142
|
const message = { type: OAUTH_POPUP_MESSAGE_TYPE };
|
|
132
143
|
opener?.postMessage(message, win.location.origin);
|
|
133
144
|
const channel = openChannel(win);
|
|
134
|
-
channel
|
|
135
|
-
channel
|
|
145
|
+
channel.postMessage(message);
|
|
146
|
+
channel.close();
|
|
136
147
|
win.close();
|
|
137
148
|
return true;
|
|
138
149
|
}
|
|
@@ -12,9 +12,6 @@ function useLoginView() {
|
|
|
12
12
|
const { context: placementContext } = useWebPlacementContext();
|
|
13
13
|
const queryClient = useQueryClient();
|
|
14
14
|
const errorRuntime = useShellWebErrorRuntime();
|
|
15
|
-
const oauthLaunchClient = useAuthOAuthLaunchClient({
|
|
16
|
-
required: true
|
|
17
|
-
});
|
|
18
15
|
|
|
19
16
|
const state = useLoginViewState({ placementContext });
|
|
20
17
|
const validation = useLoginViewValidation({ state });
|
|
@@ -23,7 +20,7 @@ function useLoginView() {
|
|
|
23
20
|
validation,
|
|
24
21
|
queryClient,
|
|
25
22
|
errorRuntime,
|
|
26
|
-
oauthLaunchClient
|
|
23
|
+
oauthLaunchClient: useAuthOAuthLaunchClient()
|
|
27
24
|
});
|
|
28
25
|
|
|
29
26
|
onMounted(actions.initializeOnMounted);
|
|
@@ -37,6 +34,12 @@ function useLoginView() {
|
|
|
37
34
|
isLogin: state.isLogin,
|
|
38
35
|
isRegister: state.isRegister,
|
|
39
36
|
isEmailConfirmationPending: state.isEmailConfirmationPending,
|
|
37
|
+
canUsePasswordLogin: state.canUsePasswordLogin,
|
|
38
|
+
canRegister: state.canRegister,
|
|
39
|
+
canRequestPasswordRecovery: state.canRequestPasswordRecovery,
|
|
40
|
+
canUseOtp: state.canUseOtp,
|
|
41
|
+
canUseOAuth: state.canUseOAuth,
|
|
42
|
+
canResendEmailConfirmation: state.canResendEmailConfirmation,
|
|
40
43
|
emailConfirmationMessage: state.emailConfirmationMessage,
|
|
41
44
|
showRememberedAccount: state.showRememberedAccount,
|
|
42
45
|
switchMode: state.switchMode,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { runAuthSignOutFlow } from "@jskit-ai/auth-core/client/signOutFlow";
|
|
2
2
|
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
3
|
-
import { isAuthGuardRuntime } from "./authGuardRuntime.js";
|
|
4
3
|
import { authHttpRequest, clearAuthCsrfTokenCache } from "./authHttpClient.js";
|
|
5
|
-
import {
|
|
4
|
+
import { useRequiredAuthGuardRuntime } from "./inject.js";
|
|
6
5
|
import { normalizeAuthReturnToPath } from "../lib/returnToPath.js";
|
|
7
6
|
import { useJskitText } from "../i18n.js";
|
|
8
7
|
|
|
@@ -34,31 +33,30 @@ async function waitForSignedOutState({ attempts = 4, delayMs = 120 } = {}) {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
function createHttpLogoutApi() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!wasAuthenticated) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
36
|
+
async function logout() {
|
|
37
|
+
const initialSession = await readSessionState();
|
|
38
|
+
const wasAuthenticated = Boolean(initialSession?.authenticated);
|
|
39
|
+
await authHttpRequest(SIGN_OUT_ENDPOINT, { method: "POST" });
|
|
40
|
+
|
|
41
|
+
const signedOut = await waitForSignedOutState();
|
|
42
|
+
if (signedOut) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
if (!wasAuthenticated) {
|
|
47
|
+
return;
|
|
53
48
|
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
if (!isAuthGuardRuntime(authGuardRuntime)) {
|
|
59
|
-
throw new TypeError("performSignOutRequest requires authGuardRuntime from useAuthGuardRuntime().");
|
|
50
|
+
throw new Error(useJskitText().t("jskit.auth.signOut.serverSessionActive"));
|
|
60
51
|
}
|
|
61
52
|
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
logout
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @param {{ authGuardRuntime: import("../types.js").AuthGuardRuntime }} options */
|
|
59
|
+
async function performSignOutRequest({ authGuardRuntime }) {
|
|
62
60
|
await runAuthSignOutFlow({
|
|
63
61
|
authApi: createHttpLogoutApi(),
|
|
64
62
|
clearCsrfTokenCache: clearAuthCsrfTokenCache
|
|
@@ -72,17 +70,22 @@ async function performSignOutRequest({ authGuardRuntime } = {}) {
|
|
|
72
70
|
return guardState;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
if (!isAuthGuardRuntime(authGuardRuntime)) {
|
|
80
|
-
throw new TypeError("createSignOutAction requires authGuardRuntime from useAuthGuardRuntime().");
|
|
81
|
-
}
|
|
73
|
+
function noReturnToPath() {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
82
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @param {{
|
|
79
|
+
* currentSurface?: import("vue").Ref<string>,
|
|
80
|
+
* goToEntry: (target: { resolvedRoute: string }) => unknown,
|
|
81
|
+
* authGuardRuntime: import("../types.js").AuthGuardRuntime,
|
|
82
|
+
* returnTo?: string,
|
|
83
|
+
* resolveReturnToPath?: () => string
|
|
84
|
+
* }} options
|
|
85
|
+
*/
|
|
86
|
+
function createSignOutAction({ currentSurface, goToEntry, authGuardRuntime, returnTo = "", resolveReturnToPath = noReturnToPath }) {
|
|
83
87
|
return async function signOut() {
|
|
84
|
-
const resolvedByCallback =
|
|
85
|
-
typeof resolveReturnToPath === "function" ? normalizeAuthReturnToPath(resolveReturnToPath(), "") : "";
|
|
88
|
+
const resolvedByCallback = normalizeAuthReturnToPath(resolveReturnToPath(), "");
|
|
86
89
|
const resolvedByOption = normalizeAuthReturnToPath(returnTo, "");
|
|
87
90
|
const resolvedByCurrentSurface = normalizeAuthReturnToPath(currentSurface?.value, "");
|
|
88
91
|
const resolvedReturnToPath = resolvedByCallback || resolvedByOption || resolvedByCurrentSurface || "/";
|
|
@@ -104,19 +107,25 @@ function createSignOutAction({ currentSurface, goToEntry, authGuardRuntime, retu
|
|
|
104
107
|
};
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
/**
|
|
111
|
+
* @param {{
|
|
112
|
+
* currentSurface?: import("vue").Ref<string>,
|
|
113
|
+
* goToEntry: (target: { resolvedRoute: string }) => unknown,
|
|
114
|
+
* authGuardRuntime?: import("../types.js").AuthGuardRuntime,
|
|
115
|
+
* returnTo?: string,
|
|
116
|
+
* resolveReturnToPath?: () => string
|
|
117
|
+
* }} options
|
|
118
|
+
*/
|
|
119
|
+
function useSignOut({ currentSurface, goToEntry, authGuardRuntime = useRequiredAuthGuardRuntime(), returnTo, resolveReturnToPath }) {
|
|
120
|
+
return {
|
|
115
121
|
signOut: createSignOutAction({
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
currentSurface,
|
|
123
|
+
goToEntry,
|
|
124
|
+
authGuardRuntime,
|
|
125
|
+
returnTo,
|
|
126
|
+
resolveReturnToPath
|
|
118
127
|
})
|
|
119
|
-
}
|
|
128
|
+
};
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
export { useSignOut, createSignOutAction, performSignOutRequest };
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { computed, markRaw, shallowRef } from "vue";
|
|
2
2
|
import { defineStore } from "pinia";
|
|
3
|
-
import {
|
|
4
|
-
import { EMPTY_AUTH_GUARD_RUNTIME, EMPTY_AUTH_GUARD_STATE } from "../runtime/inject.js";
|
|
3
|
+
import { NO_AUTH_GUARD_RUNTIME, NO_AUTH_GUARD_STATE } from "../runtime/inject.js";
|
|
5
4
|
|
|
6
5
|
function normalizeAuthStateValue(nextState) {
|
|
7
6
|
if (!nextState || typeof nextState !== "object") {
|
|
8
|
-
return
|
|
7
|
+
return NO_AUTH_GUARD_STATE;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
return nextState;
|
|
12
11
|
}
|
|
13
12
|
|
|
13
|
+
function stopListening() {}
|
|
14
|
+
|
|
14
15
|
export const useAuthStore = defineStore("jskit.auth-web.auth", () => {
|
|
15
|
-
const runtime = shallowRef(markRaw(
|
|
16
|
-
const authState = shallowRef(
|
|
17
|
-
let unsubscribe =
|
|
16
|
+
const runtime = shallowRef(markRaw(NO_AUTH_GUARD_RUNTIME));
|
|
17
|
+
const authState = shallowRef(NO_AUTH_GUARD_STATE);
|
|
18
|
+
let unsubscribe = stopListening;
|
|
18
19
|
|
|
19
20
|
function setAuthState(nextState) {
|
|
20
21
|
authState.value = normalizeAuthStateValue(nextState);
|
|
@@ -22,17 +23,12 @@ export const useAuthStore = defineStore("jskit.auth-web.auth", () => {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
function detachRuntimeSubscription() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
unsubscribe = null;
|
|
28
|
-
}
|
|
26
|
+
unsubscribe();
|
|
27
|
+
unsubscribe = stopListening;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new TypeError("useAuthStore.attachRuntime requires an auth guard runtime with subscribe().");
|
|
34
|
-
}
|
|
35
|
-
|
|
30
|
+
/** @param {import("../types.js").AuthGuardRuntime} nextRuntime */
|
|
31
|
+
function attachRuntime(nextRuntime) {
|
|
36
32
|
if (runtime.value === nextRuntime) {
|
|
37
33
|
setAuthState(nextRuntime.getState());
|
|
38
34
|
return runtime.value;
|
|
@@ -66,9 +62,9 @@ export const useAuthStore = defineStore("jskit.auth-web.auth", () => {
|
|
|
66
62
|
|
|
67
63
|
const authenticated = computed(() => authState.value.authenticated === true);
|
|
68
64
|
const username = computed(() => String(authState.value.username || ""));
|
|
69
|
-
const oauthProviders = computed(() => authState.value.oauthProviders ||
|
|
65
|
+
const oauthProviders = computed(() => authState.value.oauthProviders || NO_AUTH_GUARD_STATE.oauthProviders);
|
|
70
66
|
const oauthDefaultProvider = computed(() => String(authState.value.oauthDefaultProvider || ""));
|
|
71
|
-
const authCapabilities = computed(() => authState.value.authCapabilities ||
|
|
67
|
+
const authCapabilities = computed(() => authState.value.authCapabilities || NO_AUTH_GUARD_STATE.authCapabilities);
|
|
72
68
|
|
|
73
69
|
return {
|
|
74
70
|
runtime,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The values auth-web's client hands out and receives across files, for its own modules and for the packages that use
|
|
2
|
+
// the `client.auth` capability.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The session as the guard runtime knows it.
|
|
6
|
+
* @typedef {object} AuthGuardState
|
|
7
|
+
* @property {boolean} authenticated
|
|
8
|
+
* @property {string} username
|
|
9
|
+
* @property {string} email
|
|
10
|
+
* @property {readonly string[]} permissions
|
|
11
|
+
* @property {string} oauthDefaultProvider
|
|
12
|
+
* @property {readonly { id: string, label: string }[]} oauthProviders
|
|
13
|
+
* @property {ReturnType<typeof import("@jskit-ai/auth-core/shared/authCapabilities").normalizeAuthCapabilities>} authCapabilities
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reads and follows the session: `createAuthGuardRuntime()`, or `NO_AUTH_GUARD_RUNTIME` in an application without auth's
|
|
18
|
+
* provider.
|
|
19
|
+
* @typedef {object} AuthGuardRuntime
|
|
20
|
+
* @property {() => void} dispose
|
|
21
|
+
* @property {(options?: { sessionPath?: string, loginRoute?: string }) => Promise<AuthGuardState>} initialize
|
|
22
|
+
* @property {(options?: { sessionPath?: string }) => Promise<AuthGuardState>} refresh
|
|
23
|
+
* @property {() => AuthGuardState} getState
|
|
24
|
+
* @property {(listener: (state: AuthGuardState) => void) => () => void} subscribe
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The part of shell-web's placement runtime the guard writes the session into.
|
|
29
|
+
* @typedef {object} AuthPlacementRuntime
|
|
30
|
+
* @property {() => Record<string, any>} getContext
|
|
31
|
+
* @property {(patch: Record<string, any>, options?: { source?: string }) => void} setContext
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The part of the application's socket the guard listens on.
|
|
36
|
+
* @typedef {object} AuthRealtimeSocket
|
|
37
|
+
* @property {(eventName: string, listener: () => void) => void} on
|
|
38
|
+
* @property {(eventName: string, listener: () => void) => void} off
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The part of the optional `client.realtime` capability auth-web uses, or `NO_AUTH_REALTIME` in an application without
|
|
43
|
+
* it.
|
|
44
|
+
* @typedef {object} AuthRealtime
|
|
45
|
+
* @property {AuthRealtimeSocket} socket
|
|
46
|
+
* @property {(prepare: () => unknown) => () => void} setBeforeReconnect Sets the step recovery runs before reconnecting; returns the function that removes it.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The part of the `client.shell` capability auth-web uses.
|
|
51
|
+
* @typedef {object} AuthShell
|
|
52
|
+
* @property {AuthPlacementRuntime} placement
|
|
53
|
+
* @property {{ refresh: (reason: string) => unknown }} bootstrap
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Opens a provider's sign-in page: in this page, in a window of its own from a framed page, or in a mobile application's
|
|
58
|
+
* browser.
|
|
59
|
+
* @typedef {object} AuthOAuthLaunchClient
|
|
60
|
+
* @property {(request: { url: string }) => Promise<unknown>} open
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The part of the optional `client.mobile` capability auth-web uses.
|
|
65
|
+
* @typedef {object} AuthMobile
|
|
66
|
+
* @property {AuthOAuthLaunchClient} [oauthLaunch] Present when the application signs in through its own browser.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The part of shell-web's error runtime that tells the user about a sign-in.
|
|
71
|
+
* @typedef {object} AuthErrorRuntime
|
|
72
|
+
* @property {(event: { source: string, message: string, severity: string, channel: string, dedupeKey: string, dedupeWindowMs: number }) => unknown} report
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The request a callback completes with: `authHttpRequest()`, or the sign-in view's own.
|
|
77
|
+
* @typedef {(path: string, options: { method?: string, body?: unknown }) => Promise<any>} AuthRequest
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/** @typedef {ReturnType<typeof import("./composables/loginView/useLoginViewState.js").useLoginViewState>} LoginViewState */
|
|
81
|
+
|
|
82
|
+
/** @typedef {ReturnType<typeof import("./composables/loginView/useLoginViewValidation.js").useLoginViewValidation>} LoginViewValidation */
|
|
83
|
+
|
|
84
|
+
/** @typedef {ReturnType<typeof import("./runtime/authClient.js").createAuthClient>} AuthClient */
|
|
85
|
+
|
|
86
|
+
export {};
|
|
@@ -4,6 +4,7 @@ import { useRoute } from "vue-router";
|
|
|
4
4
|
import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
|
|
5
5
|
import ShellMenuLinkItem from "@jskit-ai/shell-web/client/components/ShellMenuLinkItem";
|
|
6
6
|
import { appendAccountReturnToIfNeeded } from "../lib/profileMenuLinkTarget.js";
|
|
7
|
+
import { pageLocation } from "../browser.js";
|
|
7
8
|
import { useJskitText } from "../i18n.js";
|
|
8
9
|
|
|
9
10
|
const props = defineProps({
|
|
@@ -30,10 +31,7 @@ const { text } = useJskitText();
|
|
|
30
31
|
const { context: placementContext } = useWebPlacementContext();
|
|
31
32
|
|
|
32
33
|
function resolveWindowHref() {
|
|
33
|
-
|
|
34
|
-
return "/";
|
|
35
|
-
}
|
|
36
|
-
return String(window.location.href || "").trim() || "/";
|
|
34
|
+
return String(pageLocation()?.href || "").trim() || "/";
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
const resolvedTo = computed(() =>
|
|
@@ -237,40 +237,14 @@
|
|
|
237
237
|
</template>
|
|
238
238
|
|
|
239
239
|
<script setup>
|
|
240
|
-
import { onMounted } from "vue";
|
|
241
|
-
import { useQueryClient } from "@tanstack/vue-query";
|
|
242
240
|
import { mdiEye, mdiEyeOff } from "@mdi/js";
|
|
243
241
|
import { useDisplay } from "vuetify";
|
|
244
|
-
import {
|
|
245
|
-
import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
|
|
246
|
-
import { useAuthOAuthLaunchClient } from "../runtime/inject.js";
|
|
247
|
-
import { useLoginViewState } from "../composables/loginView/useLoginViewState.js";
|
|
248
|
-
import { useLoginViewValidation } from "../composables/loginView/useLoginViewValidation.js";
|
|
249
|
-
import { useLoginViewActions } from "../composables/loginView/useLoginViewActions.js";
|
|
250
|
-
import { useSessionRecheckOnShow } from "../composables/loginView/useSessionRecheckOnShow.js";
|
|
242
|
+
import { useLoginView } from "../runtime/useLoginView.js";
|
|
251
243
|
import { useJskitText } from "../i18n.js";
|
|
252
244
|
|
|
253
|
-
const {
|
|
254
|
-
context: placementContext
|
|
255
|
-
} = useWebPlacementContext();
|
|
256
|
-
const queryClient = useQueryClient();
|
|
257
|
-
const errorRuntime = useShellWebErrorRuntime();
|
|
258
245
|
const { mobile: isMobileViewport } = useDisplay({ mobileBreakpoint: 960 });
|
|
259
246
|
const { t } = useJskitText();
|
|
260
247
|
|
|
261
|
-
const state = useLoginViewState({ placementContext });
|
|
262
|
-
const validation = useLoginViewValidation({ state });
|
|
263
|
-
const actions = useLoginViewActions({
|
|
264
|
-
state,
|
|
265
|
-
validation,
|
|
266
|
-
queryClient,
|
|
267
|
-
errorRuntime,
|
|
268
|
-
oauthLaunchClient: useAuthOAuthLaunchClient()
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
onMounted(actions.initializeOnMounted);
|
|
272
|
-
useSessionRecheckOnShow(actions.redirectIfSignedIn);
|
|
273
|
-
|
|
274
248
|
const {
|
|
275
249
|
authTitle,
|
|
276
250
|
authSubtitle,
|
|
@@ -308,25 +282,19 @@ const {
|
|
|
308
282
|
registerConfirmationResendPending,
|
|
309
283
|
oauthProviders,
|
|
310
284
|
loading,
|
|
311
|
-
submitLabel
|
|
312
|
-
} = state;
|
|
313
|
-
|
|
314
|
-
const {
|
|
285
|
+
submitLabel,
|
|
315
286
|
emailErrorMessages,
|
|
316
287
|
passwordErrorMessages,
|
|
317
288
|
confirmPasswordErrorMessages,
|
|
318
289
|
otpCodeErrorMessages,
|
|
319
|
-
canSubmit
|
|
320
|
-
} = validation;
|
|
321
|
-
|
|
322
|
-
const {
|
|
290
|
+
canSubmit,
|
|
323
291
|
submitAuth,
|
|
324
292
|
requestOtpCode,
|
|
325
293
|
resendRegisterConfirmationEmail,
|
|
326
294
|
oauthProviderIcon,
|
|
327
295
|
startOAuthSignIn,
|
|
328
296
|
oauthProviderButtonLabel
|
|
329
|
-
} =
|
|
297
|
+
} = useLoginView();
|
|
330
298
|
|
|
331
299
|
function togglePasswordVisibility() {
|
|
332
300
|
showPassword.value = !showPassword.value;
|