@frigear-nu/account 0.6.3 → 0.7.0
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/README.md +1 -1
- package/dist/module.d.mts +0 -20
- package/dist/module.json +1 -1
- package/dist/module.mjs +17 -25
- package/dist/runtime/app/components/Account/AccountAvatarField.vue +112 -0
- package/dist/runtime/app/components/Account/AccountMenu.d.vue.ts +1 -1
- package/dist/runtime/app/components/Account/AccountMenu.vue +8 -10
- package/dist/runtime/app/components/Account/AccountMenu.vue.d.ts +1 -1
- package/dist/runtime/app/components/Account/AccountSignedInApps.vue +3 -1
- package/dist/runtime/app/composables/index.d.ts +2 -0
- package/dist/runtime/app/composables/index.js +1 -0
- package/dist/runtime/app/composables/useAccount.d.ts +2 -0
- package/dist/runtime/app/composables/useAccount.js +15 -1
- package/dist/runtime/app/composables/useAccountAreas.d.ts +21 -0
- package/dist/runtime/app/composables/useAccountAreas.js +12 -0
- package/dist/runtime/app/composables/useAccountNav.js +1 -2
- package/dist/runtime/app/middleware/preload.js +6 -0
- package/dist/runtime/app/pages/api-tokens.vue +31 -28
- package/dist/runtime/app/pages/profile.vue +38 -15
- package/dist/runtime/app/pages/security.vue +4 -2
- package/dist/runtime/app/plugins/preload.client.js +5 -0
- package/dist/runtime/app/utils/avatar-image.d.ts +34 -0
- package/dist/runtime/app/utils/avatar-image.js +61 -0
- package/dist/runtime/app/utils/mcp-connect.d.ts +27 -0
- package/dist/runtime/app/utils/mcp-connect.js +70 -0
- package/dist/runtime/app/utils/profile.d.ts +5 -4
- package/dist/runtime/app/utils/profile.js +1 -1
- package/dist/runtime/i18n/lang/da.json +48 -20
- package/dist/runtime/i18n/lang/en.json +47 -19
- package/dist/runtime/menus.js +1 -14
- package/dist/runtime/utils/areas.d.ts +7 -0
- package/dist/runtime/utils/areas.js +4 -0
- package/package.json +15 -11
- package/dist/runtime/app/middleware/bootstrap.js +0 -6
- package/dist/runtime/app/pages/documents.vue +0 -54
- package/dist/runtime/app/plugins/bootstrap.client.js +0 -5
- package/dist/runtime/app/utils/documents.d.ts +0 -8
- package/dist/runtime/app/utils/documents.js +0 -7
- /package/dist/runtime/app/{pages/documents.d.vue.ts → components/Account/AccountAvatarField.d.vue.ts} +0 -0
- /package/dist/runtime/app/{pages/documents.vue.d.ts → components/Account/AccountAvatarField.vue.d.ts} +0 -0
- /package/dist/runtime/app/middleware/{bootstrap.d.ts → preload.d.ts} +0 -0
- /package/dist/runtime/app/plugins/{bootstrap.client.d.ts → preload.client.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @frigear-nu/account
|
|
2
2
|
|
|
3
|
-
A module for the account area (profile, security,
|
|
3
|
+
A module for the account area (profile, security, API tokens pages) in the main frigear app. Migrated from
|
|
4
4
|
[`nuxt-frigear-nu`](https://github.com/Frigear-nu/nuxt-frigear-nu)'s `app/pages/account/**`.
|
|
5
5
|
|
|
6
6
|
## Features
|
package/dist/module.d.mts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { Permission } from '@frigear-nu/auth/access';
|
|
3
2
|
|
|
4
|
-
/** A downloadable file listed on the documents page. */
|
|
5
|
-
type AccountDocument = {
|
|
6
|
-
id: string;
|
|
7
|
-
/** A string, or a map of locale -> string (falls back to `en`, then the first value). */
|
|
8
|
-
label: string | Record<string, string>;
|
|
9
|
-
/** Where the file is served from, e.g. `/assets/files/handbook.pdf`. */
|
|
10
|
-
path: string;
|
|
11
|
-
icon?: string;
|
|
12
|
-
/**
|
|
13
|
-
* The permission (`resource:action`) a user must hold to see the document listed. Omit to show it to every
|
|
14
|
-
* signed-in user. Needs `@frigear-nu/authorization`; without it a document with a permission is never listed. This only
|
|
15
|
-
* decides what is *listed*: a file in `public/` can still be fetched by anyone who knows its URL.
|
|
16
|
-
*/
|
|
17
|
-
permission?: Permission;
|
|
18
|
-
};
|
|
19
3
|
type PublicModuleOptions = {
|
|
20
4
|
pages: {
|
|
21
5
|
index?: string;
|
|
22
6
|
profile?: string;
|
|
23
7
|
security?: string;
|
|
24
|
-
documents?: string;
|
|
25
8
|
apiTokens?: string;
|
|
26
9
|
};
|
|
27
|
-
documents: AccountDocument[];
|
|
28
10
|
/** `@frigear-nu/oauth-server` is installed: the Security page lists the applications the user is signed in to. */
|
|
29
11
|
signedInApps?: boolean;
|
|
30
12
|
};
|
|
@@ -41,10 +23,8 @@ type ModuleOptions = {
|
|
|
41
23
|
index?: string | boolean;
|
|
42
24
|
profile?: string | boolean;
|
|
43
25
|
security?: string | boolean;
|
|
44
|
-
documents?: string | boolean;
|
|
45
26
|
apiTokens?: string | boolean;
|
|
46
27
|
};
|
|
47
|
-
documents?: AccountDocument[];
|
|
48
28
|
};
|
|
49
29
|
};
|
|
50
30
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, hasNuxtModule, addImports, addTypeTemplate, addRouteMiddleware, addPlugin, addComponentsDir } from '@nuxt/kit';
|
|
2
|
-
import { registerModule, inlineModuleRuntime, registerTailwindSource, registerLocales, addOptionalImports, resolvePagePath, addModulePages, defineVirtualRegistry,
|
|
2
|
+
import { registerModule, inlineModuleRuntime, registerTailwindSource, registerLocales, addOptionalImports, resolvePagePath, addModulePages, servePreloadArea, defineVirtualRegistry, getPreloadProviders, addOptionalMenuSource, serverModuleDependencies } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { localizedRoutePatterns, guardPages } from '@frigear-nu/auth/utils';
|
|
4
4
|
|
|
5
5
|
function withAppMiddleware(existing, name) {
|
|
@@ -47,25 +47,18 @@ const module$1 = defineNuxtModule({
|
|
|
47
47
|
available: () => hasNuxtModule("@frigear-nu/menu", nuxt),
|
|
48
48
|
fallback: "undefined",
|
|
49
49
|
fallbackType: "undefined"
|
|
50
|
-
}, {
|
|
51
|
-
// `@frigear-nu/authorization` is optional: without it nothing can be checked, so permission-gated documents are hidden.
|
|
52
|
-
name: "useAuthorization",
|
|
53
|
-
available: () => hasNuxtModule("@frigear-nu/authorization", nuxt),
|
|
54
|
-
fallback: "undefined",
|
|
55
|
-
fallbackType: "undefined"
|
|
56
50
|
}]);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
51
|
+
const removed = settings;
|
|
52
|
+
if (removed.documents !== void 0 || removed.pages?.documents !== void 0) {
|
|
53
|
+
throw new Error("[@frigear-nu/account] `account.settings.documents` and `account.settings.pages.documents` were removed: install `@frigear-nu/documents` and upload the files through `/admin/documents`. `frigear-nu upgrade` removes the options.");
|
|
61
54
|
}
|
|
62
55
|
addImports([
|
|
63
56
|
{ name: "useAccount", from: resolver.resolve("./runtime/app/composables/useAccount") },
|
|
64
|
-
{ name: "useAccountNav", from: resolver.resolve("./runtime/app/composables/useAccountNav") }
|
|
57
|
+
{ name: "useAccountNav", from: resolver.resolve("./runtime/app/composables/useAccountNav") },
|
|
58
|
+
{ name: "useAccountAreas", from: resolver.resolve("./runtime/app/composables/useAccountAreas") }
|
|
65
59
|
]);
|
|
66
60
|
const profilePath = resolvePagePath(settings.pages?.profile, "/account/profile");
|
|
67
61
|
const securityPath = resolvePagePath(settings.pages?.security, "/account/security");
|
|
68
|
-
const documentsPath = resolvePagePath(settings.pages?.documents, "/account/documents");
|
|
69
62
|
const withApiTokens = nuxt.options.authentication?.apiTokens !== false;
|
|
70
63
|
const apiTokensPath = withApiTokens ? resolvePagePath(settings.pages?.apiTokens, "/account/api-tokens") : void 0;
|
|
71
64
|
const indexPath = withMenus ? resolvePagePath(settings.pages?.index, "/account") : void 0;
|
|
@@ -76,8 +69,7 @@ const module$1 = defineNuxtModule({
|
|
|
76
69
|
console.warn("[@frigear-nu/account] `settings.pages.index` was set, but `@frigear-nu/menu` is not installed - skipping the dashboard page.");
|
|
77
70
|
}
|
|
78
71
|
nuxt.options.runtimeConfig.public.account = {
|
|
79
|
-
pages: { index: indexPath, profile: profilePath, security: securityPath,
|
|
80
|
-
documents: settings.documents ?? [],
|
|
72
|
+
pages: { index: indexPath, profile: profilePath, security: securityPath, apiTokens: apiTokensPath },
|
|
81
73
|
signedInApps: false
|
|
82
74
|
};
|
|
83
75
|
nuxt.hook("modules:done", () => {
|
|
@@ -86,11 +78,10 @@ const module$1 = defineNuxtModule({
|
|
|
86
78
|
addModulePages("@frigear-nu/account", resolver, [
|
|
87
79
|
{ name: "account-index", path: indexPath, file: "./runtime/app/pages/index.vue" },
|
|
88
80
|
{ name: "account-profile", path: profilePath, file: "./runtime/app/pages/profile.vue" },
|
|
89
|
-
{ name: "account-documents", path: documentsPath, file: "./runtime/app/pages/documents.vue" },
|
|
90
81
|
{ name: "account-security", path: securityPath, file: "./runtime/app/pages/security.vue" },
|
|
91
82
|
{ name: "account-api-tokens", path: apiTokensPath, file: "./runtime/app/pages/api-tokens.vue" }
|
|
92
83
|
]);
|
|
93
|
-
const outside = [indexPath, profilePath, securityPath,
|
|
84
|
+
const outside = [indexPath, profilePath, securityPath, apiTokensPath].filter((path) => !!path && path !== "/account" && !path.startsWith("/account/"));
|
|
94
85
|
const areaBase = ["/account", "/account/**", ...outside];
|
|
95
86
|
const areaPatterns = localizedRoutePatterns(nuxt, areaBase);
|
|
96
87
|
if (settings.layout !== false) {
|
|
@@ -107,27 +98,28 @@ const module$1 = defineNuxtModule({
|
|
|
107
98
|
} else {
|
|
108
99
|
console.warn("[@frigear-nu/account] @frigear-nu/authorization is not installed: the account pages are not guarded. Install it and guard `/account/**` yourself.");
|
|
109
100
|
}
|
|
101
|
+
servePreloadArea(nuxt, { area: "account" });
|
|
110
102
|
defineVirtualRegistry(nuxt, {
|
|
111
|
-
filename: "account/
|
|
112
|
-
alias: "#account/
|
|
113
|
-
collect: () =>
|
|
103
|
+
filename: "account/preload.mjs",
|
|
104
|
+
alias: "#account/preload",
|
|
105
|
+
collect: () => getPreloadProviders(nuxt, "account").map((provider) => provider.key),
|
|
114
106
|
contents: (keys) => `export const keys = ${JSON.stringify(keys)}
|
|
115
107
|
`
|
|
116
108
|
});
|
|
117
109
|
addTypeTemplate({
|
|
118
|
-
filename: "types/account-
|
|
119
|
-
getContents: () => `declare module '#account/
|
|
110
|
+
filename: "types/account-preload.d.ts",
|
|
111
|
+
getContents: () => `declare module '#account/preload' {
|
|
120
112
|
export const keys: string[]
|
|
121
113
|
}
|
|
122
114
|
export {}
|
|
123
115
|
`
|
|
124
116
|
});
|
|
125
|
-
addRouteMiddleware({ name: "account-
|
|
126
|
-
addPlugin({ src: resolver.resolve("./runtime/app/plugins/
|
|
117
|
+
addRouteMiddleware({ name: "account-preload", path: resolver.resolve("./runtime/app/middleware/preload") });
|
|
118
|
+
addPlugin({ src: resolver.resolve("./runtime/app/plugins/preload.client"), mode: "client" });
|
|
127
119
|
const areaRules = nuxt.options.routeRules ||= {};
|
|
128
120
|
for (const pattern of areaPatterns) {
|
|
129
121
|
const rule = areaRules[pattern] ?? {};
|
|
130
|
-
areaRules[pattern] = { ...rule, appMiddleware: withAppMiddleware(rule.appMiddleware, "account-
|
|
122
|
+
areaRules[pattern] = { ...rule, appMiddleware: withAppMiddleware(rule.appMiddleware, "account-preload") };
|
|
131
123
|
}
|
|
132
124
|
addOptionalMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "account" });
|
|
133
125
|
addComponentsDir({
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { AVATAR_ACCEPT, AVATAR_MAX_SOURCE_BYTES, avatarUploadProblem, squareAvatar } from "../../utils/avatar-image";
|
|
3
|
+
import { computed, ref, useAccount, useAction, useConfirmDialog, useModuleT, useTemplateRef, useUserSession } from "#imports";
|
|
4
|
+
defineOptions({ name: "AccountAvatarField" });
|
|
5
|
+
const t = useModuleT("account.profile.avatar");
|
|
6
|
+
const { user } = useUserSession();
|
|
7
|
+
const { uploadAvatar, removeAvatar } = useAccount();
|
|
8
|
+
const confirm = useConfirmDialog();
|
|
9
|
+
const uploadAction = useAction();
|
|
10
|
+
const removeAction = useAction();
|
|
11
|
+
const fileInput = useTemplateRef("fileInput");
|
|
12
|
+
const dragging = ref(false);
|
|
13
|
+
const sessionUser = computed(() => user.value);
|
|
14
|
+
const avatar = computed(() => sessionUser.value?.avatar || void 0);
|
|
15
|
+
const name = computed(() => sessionUser.value?.name ?? "");
|
|
16
|
+
const busy = computed(() => uploadAction.busy.value || removeAction.busy.value);
|
|
17
|
+
function problemText(problem) {
|
|
18
|
+
return problem === "too_large" ? t("tooLarge", "The image is too large. Choose one under {size}.", { size: `${Math.round(AVATAR_MAX_SOURCE_BYTES / 1024 / 1024)} MB` }) : t("wrongType", "Choose an image, such as a PNG, JPEG or WebP file.");
|
|
19
|
+
}
|
|
20
|
+
async function save(file) {
|
|
21
|
+
await uploadAction.run(async () => {
|
|
22
|
+
try {
|
|
23
|
+
return await uploadAvatar(await squareAvatar(file));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const problem = avatarUploadProblem(error);
|
|
26
|
+
throw problem ? new Error(problemText(problem)) : error;
|
|
27
|
+
}
|
|
28
|
+
}, { success: t("saved", "Photo saved"), error: t("saveFailed", "Could not save your photo.") });
|
|
29
|
+
}
|
|
30
|
+
function onFile(event) {
|
|
31
|
+
const input = event.target;
|
|
32
|
+
const file = input.files?.[0];
|
|
33
|
+
input.value = "";
|
|
34
|
+
if (file) void save(file);
|
|
35
|
+
}
|
|
36
|
+
function onDrop(event) {
|
|
37
|
+
dragging.value = false;
|
|
38
|
+
const file = event.dataTransfer?.files?.[0];
|
|
39
|
+
if (file && !busy.value) void save(file);
|
|
40
|
+
}
|
|
41
|
+
async function onRemove() {
|
|
42
|
+
const confirmed = await confirm({
|
|
43
|
+
title: t("removeConfirm.title", "Remove your photo?"),
|
|
44
|
+
description: t("removeConfirm.description", "Your photo is removed for everyone. Your initials are shown instead."),
|
|
45
|
+
confirmText: t("remove", "Remove photo"),
|
|
46
|
+
destructive: true
|
|
47
|
+
});
|
|
48
|
+
if (!confirmed) return;
|
|
49
|
+
await removeAction.run(() => removeAvatar(), { success: t("removed", "Photo removed"), error: t("removeFailed", "Could not remove your photo.") });
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<div class="flex flex-wrap items-center gap-4">
|
|
55
|
+
<div
|
|
56
|
+
class="relative rounded-full transition"
|
|
57
|
+
:class="dragging ? 'ring-2 ring-primary' : ''"
|
|
58
|
+
data-testid="account-avatar-drop"
|
|
59
|
+
@dragenter.prevent="dragging = true"
|
|
60
|
+
@dragover.prevent="dragging = true"
|
|
61
|
+
@dragleave.prevent="dragging = false"
|
|
62
|
+
@drop.prevent="onDrop"
|
|
63
|
+
>
|
|
64
|
+
<UAvatar
|
|
65
|
+
:src="avatar"
|
|
66
|
+
:alt="name"
|
|
67
|
+
size="3xl"
|
|
68
|
+
/>
|
|
69
|
+
<div
|
|
70
|
+
v-if="busy"
|
|
71
|
+
class="absolute inset-0 flex items-center justify-center rounded-full bg-default/70"
|
|
72
|
+
>
|
|
73
|
+
<UIcon
|
|
74
|
+
name="i-lucide-loader-circle"
|
|
75
|
+
class="size-6 animate-spin text-muted"
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<input
|
|
80
|
+
ref="fileInput"
|
|
81
|
+
type="file"
|
|
82
|
+
class="hidden"
|
|
83
|
+
:accept="AVATAR_ACCEPT"
|
|
84
|
+
data-testid="account-avatar-input"
|
|
85
|
+
@change="onFile"
|
|
86
|
+
>
|
|
87
|
+
<div class="flex flex-wrap gap-2">
|
|
88
|
+
<UButton
|
|
89
|
+
type="button"
|
|
90
|
+
icon="i-lucide-image-up"
|
|
91
|
+
color="neutral"
|
|
92
|
+
variant="outline"
|
|
93
|
+
:loading="uploadAction.busy.value"
|
|
94
|
+
:disabled="busy"
|
|
95
|
+
:label="avatar ? t('change', 'Change photo') : t('upload', 'Upload photo')"
|
|
96
|
+
@click="fileInput?.click()"
|
|
97
|
+
/>
|
|
98
|
+
<TooltipButton
|
|
99
|
+
v-if="avatar"
|
|
100
|
+
type="button"
|
|
101
|
+
icon="i-lucide-trash-2"
|
|
102
|
+
color="neutral"
|
|
103
|
+
variant="outline"
|
|
104
|
+
:loading="removeAction.busy.value"
|
|
105
|
+
:disabled="busy"
|
|
106
|
+
:label="t('remove', 'Remove photo')"
|
|
107
|
+
:tooltip="t('removeHint', 'Your initials are shown instead, for everyone')"
|
|
108
|
+
@click="onRemove"
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The signed-in user's menu: who is signed in, the `account.dropdown` menu (account, admin, sign out), and the
|
|
3
|
-
* colour mode under Appearance.
|
|
3
|
+
* colour mode under Appearance. Every area stays listed, the one you are in highlighted (`useAccountAreas`). `block` renders it as a full-width
|
|
4
4
|
* row for a sidebar footer (the admin shell), `collapsed` shrinks that row to the avatar.
|
|
5
5
|
*/
|
|
6
6
|
type __VLS_Props = {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { $fetch, computed, navigateTo, ref, useColorMode, useErrorToast, useLocaleLink, useModuleT,
|
|
2
|
+
import { $fetch, computed, navigateTo, ref, useColorMode, useErrorToast, useLocaleLink, useModuleT, useUserSession } from "#imports";
|
|
3
3
|
import { useMenu } from "#account/optional";
|
|
4
|
+
import { useAccountAreas } from "../../composables/useAccountAreas";
|
|
4
5
|
const props = defineProps({
|
|
5
6
|
block: { type: Boolean, required: false },
|
|
6
7
|
collapsed: { type: Boolean, required: false }
|
|
7
8
|
});
|
|
8
9
|
const t = useModuleT("account");
|
|
9
10
|
const { user } = useUserSession();
|
|
10
|
-
const route = useRoute();
|
|
11
11
|
const colorMode = useColorMode();
|
|
12
|
-
const { localize
|
|
12
|
+
const { localize } = useLocaleLink();
|
|
13
13
|
const showError = useErrorToast();
|
|
14
14
|
const dropdown = typeof useMenu === "function" ? useMenu("account.dropdown").data : ref([]);
|
|
15
15
|
const sessionUser = computed(() => user.value);
|
|
@@ -17,11 +17,7 @@ const displayName = computed(() => sessionUser.value?.name || sessionUser.value?
|
|
|
17
17
|
const avatar = computed(() => ({ src: sessionUser.value?.avatar || void 0, alt: displayName.value }));
|
|
18
18
|
const role = computed(() => sessionUser.value?.role || void 0);
|
|
19
19
|
const roleLabel = computed(() => role.value && role.value !== "user" ? role.value.charAt(0).toUpperCase() + role.value.slice(1) : void 0);
|
|
20
|
-
const
|
|
21
|
-
const target = strip(to);
|
|
22
|
-
const current = strip(route.path);
|
|
23
|
-
return current === target || target !== "/" && current.startsWith(`${target}/`);
|
|
24
|
-
};
|
|
20
|
+
const { current } = useAccountAreas();
|
|
25
21
|
const runAction = async (item) => {
|
|
26
22
|
try {
|
|
27
23
|
await $fetch(item.to, { method: "POST" });
|
|
@@ -36,7 +32,9 @@ const toItem = (item) => item.method && item.to ? { label: item.label, icon: ite
|
|
|
36
32
|
icon: item.icon,
|
|
37
33
|
to: item.to && !item.external ? localize(item.to) : item.to,
|
|
38
34
|
external: item.external,
|
|
39
|
-
replace: item.external
|
|
35
|
+
replace: item.external,
|
|
36
|
+
// Still a link (from a sub-page it leads back to the area's start), highlighted.
|
|
37
|
+
...item.id && item.id === current.value?.id ? { active: true } : {}
|
|
40
38
|
};
|
|
41
39
|
const appearance = (label, value, icon) => ({
|
|
42
40
|
label,
|
|
@@ -48,7 +46,7 @@ const appearance = (label, value, icon) => ({
|
|
|
48
46
|
}
|
|
49
47
|
});
|
|
50
48
|
const items = computed(() => {
|
|
51
|
-
const visible =
|
|
49
|
+
const visible = dropdown.value ?? [];
|
|
52
50
|
const last = (item) => (item.order ?? 0) >= 99;
|
|
53
51
|
return [
|
|
54
52
|
sessionUser.value ? [{ type: "label", label: displayName.value, slot: "account" }] : [],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The signed-in user's menu: who is signed in, the `account.dropdown` menu (account, admin, sign out), and the
|
|
3
|
-
* colour mode under Appearance.
|
|
3
|
+
* colour mode under Appearance. Every area stays listed, the one you are in highlighted (`useAccountAreas`). `block` renders it as a full-width
|
|
4
4
|
* row for a sidebar footer (the admin shell), `collapsed` shrinks that row to the avatar.
|
|
5
5
|
*/
|
|
6
6
|
type __VLS_Props = {
|
|
@@ -57,6 +57,7 @@ const menu = (session) => [[
|
|
|
57
57
|
|
|
58
58
|
<template>
|
|
59
59
|
<SectionCard
|
|
60
|
+
id="signed-in-apps"
|
|
60
61
|
:title="t('title', 'Signed-in apps')"
|
|
61
62
|
:description="t('description', 'Apps you signed in to with your account. Signing out of an app ends its access on every device. Changing your password or email signs them all out.')"
|
|
62
63
|
:loading="loading"
|
|
@@ -66,11 +67,12 @@ const menu = (session) => [[
|
|
|
66
67
|
v-if="sessions.length"
|
|
67
68
|
#actions
|
|
68
69
|
>
|
|
69
|
-
<
|
|
70
|
+
<TooltipButton
|
|
70
71
|
color="neutral"
|
|
71
72
|
variant="outline"
|
|
72
73
|
icon="i-lucide-log-out"
|
|
73
74
|
:label="t('signOutAll', 'Sign out of all apps')"
|
|
75
|
+
:tooltip="t('signOutAllHint', 'Every app listed here has to ask you to sign in again')"
|
|
74
76
|
@click="signOutAll"
|
|
75
77
|
/>
|
|
76
78
|
</template>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { useAccount } from './useAccount.js';
|
|
2
2
|
export { useAccountNav } from './useAccountNav.js';
|
|
3
3
|
export type { AccountNavItem } from './useAccountNav.js';
|
|
4
|
+
export { useAccountAreas } from './useAccountAreas.js';
|
|
5
|
+
export type { AccountArea } from './useAccountAreas.js';
|
|
@@ -20,6 +20,8 @@ export declare const useAccount: () => {
|
|
|
20
20
|
newPassword: string;
|
|
21
21
|
confirmNewPassword: string;
|
|
22
22
|
}) => Promise<ProfileDto>;
|
|
23
|
+
uploadAvatar: (file: Blob) => Promise<ProfileDto>;
|
|
24
|
+
removeAvatar: () => Promise<unknown>;
|
|
23
25
|
pending: import("vue").Ref<boolean, boolean>;
|
|
24
26
|
error: import("vue").Ref<string | null, string | null>;
|
|
25
27
|
};
|
|
@@ -35,5 +35,19 @@ export const useAccount = () => {
|
|
|
35
35
|
"Failed to change your password."
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
function uploadAvatar(file) {
|
|
39
|
+
const body = new FormData();
|
|
40
|
+
body.append("file", file);
|
|
41
|
+
return withRequest(
|
|
42
|
+
() => $fetch(usersApi.me.avatar, { method: "PUT", body }),
|
|
43
|
+
"Failed to upload your photo."
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function removeAvatar() {
|
|
47
|
+
return withRequest(
|
|
48
|
+
() => $fetch(usersApi.me.avatar, { method: "DELETE" }),
|
|
49
|
+
"Failed to remove your photo."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return { updateProfileDetails, changeEmailAddress, changePassword, uploadAvatar, removeAvatar, pending, error };
|
|
39
53
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** A signed-in area (dashboard, account, admin, ...): a link entry of the `account.dropdown` menu. */
|
|
2
|
+
export interface AccountArea {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: string;
|
|
6
|
+
/** Without the locale prefix: pass it through `useLocaleLink().localize` to link to it. */
|
|
7
|
+
to: string;
|
|
8
|
+
/** The route is in this area. */
|
|
9
|
+
active: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The signed-in areas the user can switch between: the link entries of the `account.dropdown` menu (actions such as
|
|
13
|
+
* sign out and external links are left out), with `active` on the area the route is in. Entries with a `permission`
|
|
14
|
+
* the user lacks are already dropped by the menu. Empty without `@frigear-nu/menu`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useAccountAreas(): {
|
|
17
|
+
areas: import("vue").ComputedRef<AccountArea[]>;
|
|
18
|
+
current: import("vue").ComputedRef<{
|
|
19
|
+
to: string;
|
|
20
|
+
} | undefined>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { computed, ref, useLocaleLink, useRoute } from "#imports";
|
|
2
|
+
import { useMenu } from "#account/optional";
|
|
3
|
+
import { matchArea } from "../../utils/areas.js";
|
|
4
|
+
export function useAccountAreas() {
|
|
5
|
+
const route = useRoute();
|
|
6
|
+
const { strip } = useLocaleLink();
|
|
7
|
+
const dropdown = typeof useMenu === "function" ? useMenu("account.dropdown").data : ref([]);
|
|
8
|
+
const links = computed(() => (dropdown.value ?? []).filter((item) => !!item.to && !item.method && !item.external).map((item) => ({ id: item.id ?? item.to, label: item.label, icon: item.icon, to: strip(item.to) })));
|
|
9
|
+
const current = computed(() => matchArea(links.value, strip(route.path)));
|
|
10
|
+
const areas = computed(() => links.value.map((area) => ({ ...area, active: area.id === current.value?.id })));
|
|
11
|
+
return { areas, current };
|
|
12
|
+
}
|
|
@@ -9,8 +9,7 @@ export async function useAccountNav() {
|
|
|
9
9
|
{ id: "account-overview", to: pages?.index, label: t("menu.overview.label", "Overview"), description: t("menu.overview.description", "A summary of your account."), icon: "i-lucide-layout-dashboard" },
|
|
10
10
|
{ id: "profile", to: pages?.profile, label: t("menu.profile.label", "Profile"), description: t("menu.profile.description", "Manage your profile details and email address."), icon: "i-lucide-user-round-pen" },
|
|
11
11
|
{ id: "security", to: pages?.security, label: t("menu.security.label", "Security"), description: t("menu.security.description", "Change your password and manage passkeys."), icon: "i-lucide-shield-user" },
|
|
12
|
-
{ id: "api-tokens", to: pages?.apiTokens, label: t("menu.apiTokens.label", "API tokens"), description: t("menu.apiTokens.description", "Create tokens for scripts and tools."), icon: "i-lucide-key-round" }
|
|
13
|
-
{ id: "documents", to: pages?.documents, label: t("menu.documents.label", "Documents"), description: t("menu.documents.description", "Handbooks and other files for you."), icon: "i-lucide-files" }
|
|
12
|
+
{ id: "api-tokens", to: pages?.apiTokens, label: t("menu.apiTokens.label", "API tokens"), description: t("menu.apiTokens.description", "Create tokens for scripts and tools."), icon: "i-lucide-key-round" }
|
|
14
13
|
].filter((item) => !!item.to);
|
|
15
14
|
const items = computed(() => menu ? (menu.data.value ?? []).filter((item) => !!item.to).map((item) => ({ id: item.id ?? item.to, label: item.label, description: item.description, icon: item.icon, to: item.to, external: item.external })) : fallback());
|
|
16
15
|
const links = useNavLinks(items, { exact: pages?.index ? [pages.index] : [] });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { authApi } from "@frigear-nu/auth/api";
|
|
3
3
|
import AccountApiTokenSlideover from "../components/Account/AccountApiTokenSlideover.vue";
|
|
4
|
-
import {
|
|
4
|
+
import { mcpConnectTabs } from "../utils/mcp-connect";
|
|
5
|
+
import { $fetch, computed, ref, tableUi, useCachedFetch, useConfirmDialog, useCopyToClipboard, useErrorToast, useFormat, useLocaleLink, useModuleT, useOverlay, useRequestURL, useRuntimeConfig, useToast } from "#imports";
|
|
5
6
|
defineOptions({ name: "AccountApiTokensPage" });
|
|
6
7
|
const t = useModuleT("account.apiTokens");
|
|
7
8
|
const toast = useToast();
|
|
@@ -48,29 +49,18 @@ const columns = computed(() => [
|
|
|
48
49
|
{ id: "actions", meta: { class: { td: "w-px text-right" } } }
|
|
49
50
|
]);
|
|
50
51
|
const tokenStatusColors = { ok: "success", expired: "warning" };
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
52
|
+
const publicConfig = useRuntimeConfig().public;
|
|
53
|
+
const mcpConfig = publicConfig.mcpModules;
|
|
54
|
+
const mcpEnabled = publicConfig.users?.mcp === true;
|
|
55
|
+
const mcpOAuth = mcpConfig?.oauth === true;
|
|
56
|
+
const mcpUrl = `${useRequestURL().origin}${mcpConfig?.route || "/mcp"}`;
|
|
57
|
+
const { localize } = useLocaleLink();
|
|
58
|
+
const securityPath = publicConfig.account?.pages?.security;
|
|
59
|
+
const signedInAppsLink = mcpOAuth && publicConfig.account?.signedInApps && securityPath ? `${localize(securityPath)}#signed-in-apps` : void 0;
|
|
54
60
|
const tokenPlaceholder = "<your-api-token>";
|
|
55
61
|
const shownToken = computed(() => revealed.value?.token ?? tokenPlaceholder);
|
|
56
|
-
const connectTabs = computed(() =>
|
|
57
|
-
|
|
58
|
-
label: "Claude",
|
|
59
|
-
value: "claude",
|
|
60
|
-
steps: t("connect.claude.steps", "Claude.ai and Claude Desktop: open Settings \u2192 Connectors \u2192 Add custom connector, paste the URL below and sign in when asked. No token needed."),
|
|
61
|
-
code: mcpUrl,
|
|
62
|
-
extraSteps: t("connect.claude.cli", "Claude Code (uses an API token):"),
|
|
63
|
-
extraCode: `claude mcp add --transport http frigear ${mcpUrl} --header "Authorization: Bearer ${shownToken.value}"`
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
label: "ChatGPT",
|
|
67
|
-
value: "chatgpt",
|
|
68
|
-
steps: t("connect.chatgpt.steps", "ChatGPT: open Settings \u2192 Connectors \u2192 Advanced, turn on Developer mode, then create a connector with the URL below. Choose OAuth and sign in when asked. No token needed."),
|
|
69
|
-
code: mcpUrl,
|
|
70
|
-
extraSteps: void 0,
|
|
71
|
-
extraCode: void 0
|
|
72
|
-
}
|
|
73
|
-
]);
|
|
62
|
+
const connectTabs = computed(() => mcpConnectTabs({ url: mcpUrl, oauth: mcpOAuth, token: shownToken.value, t }));
|
|
63
|
+
const activeConnect = ref(connectTabs.value[0]?.value ?? "");
|
|
74
64
|
const activeTab = computed(() => connectTabs.value.find((tab) => tab.value === activeConnect.value) ?? connectTabs.value[0]);
|
|
75
65
|
</script>
|
|
76
66
|
|
|
@@ -78,9 +68,10 @@ const activeTab = computed(() => connectTabs.value.find((tab) => tab.value === a
|
|
|
78
68
|
<div class="flex flex-col gap-4">
|
|
79
69
|
<AccountHeader>
|
|
80
70
|
<template #actions>
|
|
81
|
-
<
|
|
71
|
+
<TooltipButton
|
|
82
72
|
icon="i-lucide-plus"
|
|
83
73
|
:label="t('create.submit', 'Create API token')"
|
|
74
|
+
:tooltip="t('create.submitHint', 'Make a token for scripts and tools; it is shown only once')"
|
|
84
75
|
@click="onCreate"
|
|
85
76
|
/>
|
|
86
77
|
</template>
|
|
@@ -189,7 +180,7 @@ const activeTab = computed(() => connectTabs.value.find((tab) => tab.value === a
|
|
|
189
180
|
<SectionCard
|
|
190
181
|
v-if="mcpEnabled"
|
|
191
182
|
:title="t('connect.title', 'Connect to MCP')"
|
|
192
|
-
:description="t('connect.description', 'Use your account from an AI assistant. Your API token is only filled into the commands right after you create it.')"
|
|
183
|
+
:description="mcpOAuth ? t('connect.descriptionOAuth', 'Use your account from an AI assistant: add the URL in the app, then sign in. An API token is only needed for clients that cannot sign in, and is filled into the commands right after you create it.') : t('connect.description', 'Use your account from an AI assistant. Your API token is only filled into the commands right after you create it.')"
|
|
193
184
|
>
|
|
194
185
|
<div class="flex min-w-0 flex-col gap-3">
|
|
195
186
|
<PageTabs
|
|
@@ -202,13 +193,13 @@ const activeTab = computed(() => connectTabs.value.find((tab) => tab.value === a
|
|
|
202
193
|
</p>
|
|
203
194
|
<div class="relative min-w-0">
|
|
204
195
|
<pre class="max-w-full whitespace-pre-wrap break-all rounded-md bg-elevated p-3 pr-12 text-sm"><code>{{ activeTab.code }}</code></pre>
|
|
205
|
-
<
|
|
196
|
+
<TooltipButton
|
|
206
197
|
class="absolute right-2 top-2"
|
|
207
198
|
color="neutral"
|
|
208
199
|
variant="ghost"
|
|
209
200
|
size="xs"
|
|
210
201
|
icon="i-lucide-copy"
|
|
211
|
-
:
|
|
202
|
+
:tooltip="t('copySnippetHint', 'Copy this command to your clipboard')"
|
|
212
203
|
@click="copy(activeTab.code, t('copiedSnippet', 'Copied.'))"
|
|
213
204
|
/>
|
|
214
205
|
</div>
|
|
@@ -218,18 +209,30 @@ const activeTab = computed(() => connectTabs.value.find((tab) => tab.value === a
|
|
|
218
209
|
</p>
|
|
219
210
|
<div class="relative min-w-0">
|
|
220
211
|
<pre class="max-w-full whitespace-pre-wrap break-all rounded-md bg-elevated p-3 pr-12 text-sm"><code>{{ activeTab.extraCode }}</code></pre>
|
|
221
|
-
<
|
|
212
|
+
<TooltipButton
|
|
222
213
|
class="absolute right-2 top-2"
|
|
223
214
|
color="neutral"
|
|
224
215
|
variant="ghost"
|
|
225
216
|
size="xs"
|
|
226
217
|
icon="i-lucide-copy"
|
|
227
|
-
:
|
|
218
|
+
:tooltip="t('copySnippetHint', 'Copy this command to your clipboard')"
|
|
228
219
|
@click="copy(activeTab.extraCode, t('copiedSnippet', 'Copied.'))"
|
|
229
220
|
/>
|
|
230
221
|
</div>
|
|
231
222
|
</template>
|
|
232
223
|
</template>
|
|
224
|
+
<p
|
|
225
|
+
v-if="signedInAppsLink"
|
|
226
|
+
class="text-sm text-muted"
|
|
227
|
+
>
|
|
228
|
+
{{ t("connect.signedInApps", "Apps you connect by signing in are listed under Signed-in apps on the Security page, where you can sign them out.") }}
|
|
229
|
+
<ULink
|
|
230
|
+
:to="signedInAppsLink"
|
|
231
|
+
class="text-primary"
|
|
232
|
+
>
|
|
233
|
+
{{ t("connect.signedInAppsLink", "Open signed-in apps") }}
|
|
234
|
+
</ULink>
|
|
235
|
+
</p>
|
|
233
236
|
</div>
|
|
234
237
|
</SectionCard>
|
|
235
238
|
</div>
|