@jskit-ai/users-web 0.2.2 → 0.2.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.
- package/locales/en.json +4 -0
- package/package.json +15 -3
- package/patterns/account-settings/PATTERN.md +12 -3
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsSignInMethodsSection.vue +67 -0
- package/src/client/composables/useAccountSettingsRuntime.js +70 -1
- package/test/settingsPlacementContract.test.js +4 -0
package/locales/en.json
CHANGED
|
@@ -65,6 +65,10 @@
|
|
|
65
65
|
"notifications": {
|
|
66
66
|
"saved": "Notification settings updated.",
|
|
67
67
|
"saveFailed": "Unable to update notifications."
|
|
68
|
+
},
|
|
69
|
+
"signInMethods": {
|
|
70
|
+
"unlinked": "Sign-in method removed.",
|
|
71
|
+
"unlinkFailed": "Unable to remove the sign-in method."
|
|
68
72
|
}
|
|
69
73
|
},
|
|
70
74
|
"homeTools": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/users-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@jskit-ai/uploads-image-web": "0.2.1",
|
|
17
|
-
"@jskit-ai/users-core": "0.2.
|
|
17
|
+
"@jskit-ai/users-core": "0.2.2"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@jskit-ai/auth-web": "0.2.1",
|
|
21
21
|
"@jskit-ai/http-runtime": "0.2.1",
|
|
22
|
-
"@jskit-ai/http-web": "0.2.
|
|
22
|
+
"@jskit-ai/http-web": "0.2.3",
|
|
23
23
|
"@jskit-ai/kernel": "0.2.1",
|
|
24
24
|
"@jskit-ai/shell-web": "0.2.1",
|
|
25
25
|
"@tanstack/vue-query": "^5.90.5",
|
|
@@ -208,6 +208,18 @@
|
|
|
208
208
|
"order": 300,
|
|
209
209
|
"componentToken": "local.main.account-settings.section.notifications",
|
|
210
210
|
"source": "patterns/account-settings/example/src/components/account/settings/AccountSettingsNotificationsSection.vue"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"id": "users.account.settings.sign-in-methods",
|
|
214
|
+
"target": "settings.sections",
|
|
215
|
+
"owner": "account-settings",
|
|
216
|
+
"kind": "component",
|
|
217
|
+
"surfaces": [
|
|
218
|
+
"account"
|
|
219
|
+
],
|
|
220
|
+
"order": 400,
|
|
221
|
+
"componentToken": "local.main.account-settings.section.sign-in-methods",
|
|
222
|
+
"source": "patterns/account-settings/example/src/components/account/settings/AccountSettingsSignInMethodsSection.vue"
|
|
211
223
|
}
|
|
212
224
|
]
|
|
213
225
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: users/account-settings
|
|
3
3
|
title: Account settings surface
|
|
4
|
-
summary: Compose an account settings route and profile, preference, and
|
|
5
|
-
keywords: account, notifications, preferences, profile, settings, user, vue
|
|
4
|
+
summary: Compose an account settings route and profile, preference, notification, and sign-in method sections from JSKIT user web components.
|
|
5
|
+
keywords: account, notifications, preferences, profile, settings, sign-in methods, oauth, link provider, user, vue
|
|
6
6
|
requires: @jskit-ai/users-core, @jskit-ai/users-web, @jskit-ai/shell-web
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -38,6 +38,15 @@ app's language; the app does, for example
|
|
|
38
38
|
`watch(useAccountLocale(), (code) => { if (code) i18n.global.locale.value = code; }, { immediate: true })`.
|
|
39
39
|
Section titles may be plain text, a message key or `{ key, fallback }`.
|
|
40
40
|
|
|
41
|
+
`runtime.signInMethods.methods` lists the auth provider's OAuth sign-in
|
|
42
|
+
methods as `{ provider, label, linked, canLink, canUnlink }`, read from the
|
|
43
|
+
settings security status. `link(provider)` leaves for the provider through
|
|
44
|
+
`GET /api/settings/security/oauth/:provider/start` and comes back to the current
|
|
45
|
+
page; `unlink(provider)` sends `DELETE /api/settings/security/oauth/:provider`
|
|
46
|
+
and reports the result with the standard toast. `canUnlink` is false for the
|
|
47
|
+
account's only sign-in method. Add this section only when the selected auth
|
|
48
|
+
provider offers provider linking (`providerLinking` in its capabilities).
|
|
49
|
+
|
|
41
50
|
## Invariants
|
|
42
51
|
|
|
43
52
|
- Sections use JSKIT account settings APIs rather than direct HTTP helpers.
|
|
@@ -51,7 +60,7 @@ Section titles may be plain text, a message key or `{ key, fallback }`.
|
|
|
51
60
|
|
|
52
61
|
## Example files
|
|
53
62
|
|
|
54
|
-
`example/` contains an account route and
|
|
63
|
+
`example/` contains an account route and four concrete settings sections.
|
|
55
64
|
Adapt their fields and copy while retaining the shared account runtime.
|
|
56
65
|
|
|
57
66
|
## Variation points
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
const props = defineProps({
|
|
3
|
+
runtime: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const signInMethods = props.runtime.signInMethods;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<v-sheet rounded="lg" border class="account-settings-section">
|
|
14
|
+
<v-list lines="two" class="py-0">
|
|
15
|
+
<v-list-item
|
|
16
|
+
v-for="method in signInMethods.methods.value"
|
|
17
|
+
:key="method.provider"
|
|
18
|
+
:title="method.label"
|
|
19
|
+
:subtitle="method.linked ? 'Linked' : 'Not linked'"
|
|
20
|
+
>
|
|
21
|
+
<template #append>
|
|
22
|
+
<v-btn
|
|
23
|
+
v-if="method.linked"
|
|
24
|
+
variant="text"
|
|
25
|
+
color="error"
|
|
26
|
+
:loading="signInMethods.unlinkingProvider.value === method.provider"
|
|
27
|
+
:disabled="!method.canUnlink || signInMethods.isRefreshing.value"
|
|
28
|
+
@click="signInMethods.unlink(method.provider)"
|
|
29
|
+
>
|
|
30
|
+
Unlink
|
|
31
|
+
</v-btn>
|
|
32
|
+
<v-btn
|
|
33
|
+
v-else
|
|
34
|
+
variant="tonal"
|
|
35
|
+
color="primary"
|
|
36
|
+
:disabled="!method.canLink || signInMethods.isRefreshing.value"
|
|
37
|
+
@click="signInMethods.link(method.provider)"
|
|
38
|
+
>
|
|
39
|
+
Link
|
|
40
|
+
</v-btn>
|
|
41
|
+
</template>
|
|
42
|
+
</v-list-item>
|
|
43
|
+
</v-list>
|
|
44
|
+
<p
|
|
45
|
+
v-if="signInMethods.methods.value.some((method) => method.linked && !method.canUnlink)"
|
|
46
|
+
class="account-settings-section__hint text-body-2 text-medium-emphasis mb-0"
|
|
47
|
+
>
|
|
48
|
+
Your only sign-in method can't be unlinked. Set a password or link another provider first.
|
|
49
|
+
</p>
|
|
50
|
+
</v-sheet>
|
|
51
|
+
</template>
|
|
52
|
+
|
|
53
|
+
<style scoped>
|
|
54
|
+
.account-settings-section {
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.account-settings-section__hint {
|
|
59
|
+
padding: 0 1rem 1rem;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@media (max-width: 640px) {
|
|
63
|
+
.account-settings-section :deep(.v-btn) {
|
|
64
|
+
min-height: 48px;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
@@ -72,6 +72,10 @@ function useAccountSettingsRuntime() {
|
|
|
72
72
|
requestType: "user-notification-settings"
|
|
73
73
|
});
|
|
74
74
|
const USER_PROFILE_AVATAR_DELETE_TRANSPORT = USER_SETTINGS_TRANSPORT;
|
|
75
|
+
const USER_SECURITY_SETTINGS_TRANSPORT = Object.freeze({
|
|
76
|
+
...USER_SETTINGS_TRANSPORT,
|
|
77
|
+
responseType: "user-security-settings"
|
|
78
|
+
});
|
|
75
79
|
|
|
76
80
|
const accountSettingsPath = computed(() =>
|
|
77
81
|
resolveSurfacePathFromPlacementContext(placementContext.value, "account", "/")
|
|
@@ -121,6 +125,11 @@ function useAccountSettingsRuntime() {
|
|
|
121
125
|
});
|
|
122
126
|
|
|
123
127
|
const selectedAvatarFileName = ref("");
|
|
128
|
+
// The account's OAuth sign-in methods; canEnable links one and canDisable unlinks it.
|
|
129
|
+
const signInMethodList = ref([]);
|
|
130
|
+
const signInMethodsState = reactive({
|
|
131
|
+
unlinkingProvider: ""
|
|
132
|
+
});
|
|
124
133
|
const savedLocale = ref("");
|
|
125
134
|
|
|
126
135
|
const profileInitials = computed(() => {
|
|
@@ -173,6 +182,19 @@ function useAccountSettingsRuntime() {
|
|
|
173
182
|
profileAvatar.version = nextAvatar.version == null ? null : String(nextAvatar.version);
|
|
174
183
|
}
|
|
175
184
|
|
|
185
|
+
function applySignInMethods(securityStatus) {
|
|
186
|
+
const authMethods = Array.isArray(securityStatus?.authMethods) ? securityStatus.authMethods : [];
|
|
187
|
+
signInMethodList.value = authMethods
|
|
188
|
+
.filter((method) => method?.kind === "oauth" && method.provider)
|
|
189
|
+
.map((method) => Object.freeze({
|
|
190
|
+
provider: String(method.provider),
|
|
191
|
+
label: String(method.label || method.provider),
|
|
192
|
+
linked: method.configured === true,
|
|
193
|
+
canLink: method.canEnable === true,
|
|
194
|
+
canUnlink: method.canDisable === true
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
|
|
176
198
|
function applySettingsData(payload) {
|
|
177
199
|
const data = normalizeSettingsPayload(payload);
|
|
178
200
|
|
|
@@ -192,6 +214,8 @@ function useAccountSettingsRuntime() {
|
|
|
192
214
|
notificationsForm.accountActivity = Boolean(data.notifications?.accountActivity);
|
|
193
215
|
notificationsForm.securityAlerts = ACCOUNT_SETTINGS_DEFAULTS.notifications.securityAlerts;
|
|
194
216
|
|
|
217
|
+
applySignInMethods(data.security);
|
|
218
|
+
|
|
195
219
|
applyThemePreference(preferencesForm.theme);
|
|
196
220
|
if (data.preferences?.locale) {
|
|
197
221
|
savedLocale.value = preferencesForm.locale;
|
|
@@ -314,6 +338,25 @@ function useAccountSettingsRuntime() {
|
|
|
314
338
|
}
|
|
315
339
|
});
|
|
316
340
|
|
|
341
|
+
const signInMethodUnlinkCommand = useCommand({
|
|
342
|
+
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
343
|
+
apiSuffix: () => `/settings/security/oauth/${encodeURIComponent(signInMethodsState.unlinkingProvider)}`,
|
|
344
|
+
writeMethod: "DELETE",
|
|
345
|
+
transport: USER_SECURITY_SETTINGS_TRANSPORT,
|
|
346
|
+
fallbackRunError: t("jskit.users.accountSettings.signInMethods.unlinkFailed"),
|
|
347
|
+
model: signInMethodsState,
|
|
348
|
+
onRunSuccess: (payload, { queryClient: commandQueryClient }) => {
|
|
349
|
+
applySignInMethods(payload?.securityStatus);
|
|
350
|
+
commandQueryClient.setQueryData(accountSettingsQueryKey, (current) =>
|
|
351
|
+
current ? { ...current, security: payload?.securityStatus } : current
|
|
352
|
+
);
|
|
353
|
+
},
|
|
354
|
+
messages: {
|
|
355
|
+
success: t("jskit.users.accountSettings.signInMethods.unlinked"),
|
|
356
|
+
error: t("jskit.users.accountSettings.signInMethods.unlinkFailed")
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
317
360
|
const loadingSettings = computed(() => Boolean(settingsView.isLoading));
|
|
318
361
|
const refreshingSettings = computed(() => Boolean(settingsView.isRefetching));
|
|
319
362
|
const settingsLoadError = computed(() => String(settingsView.loadError || "").trim());
|
|
@@ -346,6 +389,23 @@ function useAccountSettingsRuntime() {
|
|
|
346
389
|
await notificationsAddEdit.submit();
|
|
347
390
|
}
|
|
348
391
|
|
|
392
|
+
// Linking leaves the app for the provider and returns to this page.
|
|
393
|
+
function linkSignInMethod(provider) {
|
|
394
|
+
const params = new URLSearchParams({ returnTo: route?.fullPath || accountSettingsPath.value });
|
|
395
|
+
window.location.assign(`/api/settings/security/oauth/${encodeURIComponent(provider)}/start?${params}`);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function unlinkSignInMethod(provider) {
|
|
399
|
+
signInMethodsState.unlinkingProvider = String(provider || "");
|
|
400
|
+
try {
|
|
401
|
+
await signInMethodUnlinkCommand.run();
|
|
402
|
+
} catch {
|
|
403
|
+
// Error feedback is already handled in useCommand.
|
|
404
|
+
} finally {
|
|
405
|
+
signInMethodsState.unlinkingProvider = "";
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
349
409
|
watch(
|
|
350
410
|
() => preferencesForm.avatarSize,
|
|
351
411
|
(nextSize) => {
|
|
@@ -409,6 +469,14 @@ function useAccountSettingsRuntime() {
|
|
|
409
469
|
submit: submitNotifications
|
|
410
470
|
});
|
|
411
471
|
|
|
472
|
+
const signInMethods = Object.freeze({
|
|
473
|
+
methods: signInMethodList,
|
|
474
|
+
unlinkingProvider: computed(() => signInMethodsState.unlinkingProvider),
|
|
475
|
+
isRefreshing: refreshingSettings,
|
|
476
|
+
link: linkSignInMethod,
|
|
477
|
+
unlink: unlinkSignInMethod
|
|
478
|
+
});
|
|
479
|
+
|
|
412
480
|
return Object.freeze({
|
|
413
481
|
backTarget,
|
|
414
482
|
backNavigationTarget,
|
|
@@ -418,7 +486,8 @@ function useAccountSettingsRuntime() {
|
|
|
418
486
|
refreshSettings,
|
|
419
487
|
profile,
|
|
420
488
|
preferences,
|
|
421
|
-
notifications
|
|
489
|
+
notifications,
|
|
490
|
+
signInMethods
|
|
422
491
|
});
|
|
423
492
|
}
|
|
424
493
|
|
|
@@ -142,5 +142,9 @@ test("semantic contributions identify live package source or reusable pattern so
|
|
|
142
142
|
contribution("users.account.settings.notifications")?.source,
|
|
143
143
|
"patterns/account-settings/example/src/components/account/settings/AccountSettingsNotificationsSection.vue"
|
|
144
144
|
);
|
|
145
|
+
assert.equal(
|
|
146
|
+
contribution("users.account.settings.sign-in-methods")?.source,
|
|
147
|
+
"patterns/account-settings/example/src/components/account/settings/AccountSettingsSignInMethodsSection.vue"
|
|
148
|
+
);
|
|
145
149
|
assert.equal(contribution("users.home.settings.general"), null);
|
|
146
150
|
});
|