@frigear-nu/oauth-server 0.1.2 → 0.2.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.
Files changed (44) hide show
  1. package/dist/module.d.mts +8 -1
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +24 -20
  4. package/dist/runtime/app/components/OAuthApplicationSlideover.vue +1 -0
  5. package/dist/runtime/app/components/OAuthCredentialsModal.vue +1 -0
  6. package/dist/runtime/app/composables/useOAuthApplicationActions.d.ts +3 -0
  7. package/dist/runtime/app/composables/useOAuthApplicationActions.js +30 -13
  8. package/dist/runtime/app/composables/useOAuthApplications.d.ts +34 -13
  9. package/dist/runtime/app/composables/useOAuthApplications.js +26 -14
  10. package/dist/runtime/app/pages/admin.vue +114 -62
  11. package/dist/runtime/app/pages/applications.vue +52 -34
  12. package/dist/runtime/app/pages/authorize.vue +4 -2
  13. package/dist/runtime/i18n/lang/da.json +6 -1
  14. package/dist/runtime/i18n/lang/en.json +6 -1
  15. package/dist/runtime/menus.js +1 -0
  16. package/dist/runtime/server/middleware/oauth-cors.js +6 -5
  17. package/dist/runtime/server/routes/api/admin/application-revoke.post.js +5 -3
  18. package/dist/runtime/server/routes/api/admin/application-secret.post.js +3 -1
  19. package/dist/runtime/server/routes/api/admin/application.delete.js +4 -3
  20. package/dist/runtime/server/routes/api/admin/application.get.js +6 -3
  21. package/dist/runtime/server/routes/api/admin/application.patch.js +4 -3
  22. package/dist/runtime/server/routes/api/admin/applications.get.js +20 -8
  23. package/dist/runtime/server/routes/api/admin/applications.post.js +3 -3
  24. package/dist/runtime/server/routes/api/consent.get.js +4 -3
  25. package/dist/runtime/server/routes/oidc/authorize.get.js +5 -6
  26. package/dist/runtime/server/routes/oidc/authorize.post.js +1 -2
  27. package/dist/runtime/server/routes/oidc/openid-configuration.get.js +6 -5
  28. package/dist/runtime/server/routes/oidc/revoke.post.js +15 -3
  29. package/dist/runtime/server/routes/oidc/token.post.js +20 -5
  30. package/dist/runtime/server/utils/oauth-access.d.ts +2 -0
  31. package/dist/runtime/server/utils/oauth-access.js +7 -1
  32. package/dist/runtime/server/utils/oauth-applications.d.ts +7 -2
  33. package/dist/runtime/server/utils/oauth-applications.js +39 -12
  34. package/dist/runtime/server/utils/oauth-authorize.d.ts +8 -4
  35. package/dist/runtime/server/utils/oauth-authorize.js +10 -8
  36. package/dist/runtime/server/utils/oauth-config.d.ts +5 -0
  37. package/dist/runtime/server/utils/oauth-config.js +5 -0
  38. package/dist/runtime/server/utils/oauth-keys.js +3 -2
  39. package/dist/runtime/utils/api.d.ts +28 -0
  40. package/dist/runtime/utils/api.js +27 -0
  41. package/dist/runtime/utils/index.d.ts +1 -0
  42. package/dist/runtime/utils/index.js +1 -0
  43. package/dist/types.d.mts +1 -1
  44. package/package.json +14 -9
package/dist/module.d.mts CHANGED
@@ -175,6 +175,13 @@ type AdminApplicationDto = Omit<OAuthApplication, 'createdAt' | 'updatedAt'> & {
175
175
  /** The redirect URI the application has to accept. */
176
176
  callbackUrl: string;
177
177
  };
178
+ /** One page of `GET /api/admin/oauth-server/applications` (the shape `useTableQuery` speaks). */
179
+ type AdminApplicationsPage = {
180
+ items: AdminApplicationDto[];
181
+ total: number;
182
+ page: number;
183
+ pageSize: number;
184
+ };
178
185
  /** Returned once when an application is created. */
179
186
  type CreatedApplicationDto = AdminApplicationDto & {
180
187
  clientId: string;
@@ -221,4 +228,4 @@ declare module 'nitropack' {
221
228
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
222
229
 
223
230
  export { _default as default };
224
- export type { AdminApplicationDto, ApplicationAccessContext, ApplicationInput, AuthorizeContext, ClaimsContext, ClientType, ConsentDto, CreatedApplicationDto, ModuleOptions, OAuthApplication, OAuthServerRuntimeConfig, OAuthUser, PublicModuleOptions, TokenIssuedContext, TokenRevokedContext, TokenType, UserApplicationDto, UserRolesContext };
231
+ export type { AdminApplicationDto, AdminApplicationsPage, ApplicationAccessContext, ApplicationInput, AuthorizeContext, ClaimsContext, ClientType, ConsentDto, CreatedApplicationDto, ModuleOptions, OAuthApplication, OAuthServerRuntimeConfig, OAuthUser, PublicModuleOptions, TokenIssuedContext, TokenRevokedContext, TokenType, UserApplicationDto, UserRolesContext };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/oauth-server",
3
3
  "configKey": "oauthServer",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  import { defineNuxtModule, createResolver, hasNuxtModule, addServerHandler, addServerImportsDir, addImports } from '@nuxt/kit';
2
- import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, registerDatabaseTable, registerBootstrapProvider, inlineModuleRuntime, addModulePages, addOptionalMenuSource, moduleApiUrl } from '@frigear-nu/module-kit/utils';
2
+ import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, registerDatabaseTable, addModuleRoutes, registerBootstrapProvider, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
3
  import { adminRoute } from '@frigear-nu/admin/utils';
4
4
  import { addAuthScope, addAuthResolver } from '@frigear-nu/auth/utils';
5
5
  import { addMcpDefinitions } from '@frigear-nu/mcp/utils';
6
+ import { oidc } from '../dist/runtime/utils/api.js';
6
7
 
7
8
  const MODULE_NAME = "@frigear-nu/oauth-server";
8
- const API_NAME = "oauthServer";
9
9
  const module$1 = defineNuxtModule({
10
10
  meta: { name: MODULE_NAME, configKey: "oauthServer" },
11
11
  defaults: {
@@ -81,29 +81,33 @@ const module$1 = defineNuxtModule({
81
81
  schema: (dialect) => `./runtime/server/db/schema.${dialect}`
82
82
  });
83
83
  addServerHandler({ middleware: true, handler: resolver.resolve("./runtime/server/middleware/oauth-cors") });
84
- const handler = (file) => resolver.resolve(`./runtime/server/routes/${file}`);
85
- addServerHandler({ route: "/.well-known/openid-configuration", method: "get", handler: handler("oidc/openid-configuration.get") });
86
- addServerHandler({ route: "/.well-known/jwks.json", method: "get", handler: handler("oidc/jwks.get") });
87
- addServerHandler({ route: "/oauth/authorize", method: "get", handler: handler("oidc/authorize.get") });
88
- addServerHandler({ route: "/oauth/authorize", method: "post", handler: handler("oidc/authorize.post") });
89
- addServerHandler({ route: "/oauth/token", method: "post", handler: handler("oidc/token.post") });
90
- addServerHandler({ route: "/oauth/revoke", method: "post", handler: handler("oidc/revoke.post") });
91
- addServerHandler({ route: "/oauth/userinfo", method: "get", handler: handler("oidc/userinfo.get") });
92
- const api = (method, path, file) => addServerHandler({ route: moduleApiUrl(API_NAME, path), method, handler: handler(file) });
93
- api("get", "consent", "api/consent.get");
94
- api("get", "me/applications", "api/me-applications.get");
84
+ addModuleRoutes(resolver, [
85
+ { method: "get", path: oidc.configuration, file: "oidc/openid-configuration.get" },
86
+ { method: "get", path: oidc.jwks, file: "oidc/jwks.get" },
87
+ { method: "get", path: oidc.authorize, file: "oidc/authorize.get" },
88
+ { method: "post", path: oidc.authorize, file: "oidc/authorize.post" },
89
+ { method: "post", path: oidc.token, file: "oidc/token.post" },
90
+ { method: "post", path: oidc.revoke, file: "oidc/revoke.post" },
91
+ { method: "get", path: oidc.userinfo, file: "oidc/userinfo.get" }
92
+ ], { base: "/" });
93
+ addModuleRoutes(resolver, [
94
+ { method: "get", path: "consent", file: "api/consent.get" },
95
+ { method: "get", path: "me/applications", file: "api/me-applications.get" }
96
+ ], { base: "/api/oauth-server" });
95
97
  registerBootstrapProvider(nuxt, {
96
98
  scope: "account",
97
99
  key: "oauth-server:mine",
98
100
  handler: resolver.resolve("./runtime/server/bootstrap/my-applications")
99
101
  });
100
- api("get", "admin/applications", "api/admin/applications.get");
101
- api("post", "admin/applications", "api/admin/applications.post");
102
- api("get", "admin/applications/:id", "api/admin/application.get");
103
- api("patch", "admin/applications/:id", "api/admin/application.patch");
104
- api("delete", "admin/applications/:id", "api/admin/application.delete");
105
- api("post", "admin/applications/:id/secret", "api/admin/application-secret.post");
106
- api("post", "admin/applications/:id/revoke", "api/admin/application-revoke.post");
102
+ addModuleRoutes(resolver, [
103
+ { method: "get", path: "applications", file: "api/admin/applications.get" },
104
+ { method: "post", path: "applications", file: "api/admin/applications.post" },
105
+ { method: "get", path: "applications/:id", file: "api/admin/application.get" },
106
+ { method: "patch", path: "applications/:id", file: "api/admin/application.patch" },
107
+ { method: "delete", path: "applications/:id", file: "api/admin/application.delete" },
108
+ { method: "post", path: "applications/:id/secret", file: "api/admin/application-secret.post" },
109
+ { method: "post", path: "applications/:id/revoke", file: "api/admin/application-revoke.post" }
110
+ ], { base: "/api/admin/oauth-server" });
107
111
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
108
112
  inlineModuleRuntime(nuxt, resolver);
109
113
  if (settings.mcp === true) addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
@@ -1,6 +1,7 @@
1
1
  <script setup>
2
2
  import * as z from "zod";
3
3
  import { isNativeRedirectUri, isSecureOrigin } from "../../utils";
4
+ import { computed, reactive, useAction, useModuleT } from "#imports";
4
5
  defineOptions({ name: "OAuthApplicationSlideover" });
5
6
  const props = defineProps({
6
7
  application: { type: Object, required: false },
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { useCopyToClipboard, useModuleT } from "#imports";
2
3
  defineOptions({ name: "OAuthCredentialsModal" });
3
4
  defineProps({
4
5
  name: { type: String, required: true },
@@ -5,6 +5,9 @@ type SavedApplication = AdminApplicationDto | CreatedApplicationDto | false | un
5
5
  * Everything you can do to an application: `create` / `edit` (a `FormSlideover`), `remove`, `toggle`, `rotateSecret`,
6
6
  * `signOutEveryone`, `copyClientId` and `menu(application)` for the row menu. Toasts, confirmations and the refresh
7
7
  * of the admin list are handled here.
8
+ *
9
+ * `edit` owns the `?application=<id>` query parameter of the page it is opened from: it is set while the form is open
10
+ * and cleared when it closes, so an edit can be linked to and survives a reload (the admin page opens it again).
8
11
  */
9
12
  export declare function useOAuthApplicationActions(): {
10
13
  busy: any;
@@ -1,6 +1,7 @@
1
1
  import OAuthApplicationSlideover from "../components/OAuthApplicationSlideover.vue";
2
2
  import OAuthCredentialsModal from "../components/OAuthCredentialsModal.vue";
3
3
  import { OAUTH_APPLICATIONS_KEY, oauthApplicationsApi } from "./useOAuthApplications.js";
4
+ import { ref, refreshNuxtData, useAction, useConfirmDialog, useCopyToClipboard, useModuleT, useOverlay, useRoute, useRouter, useToast } from "#imports";
4
5
  export function useOAuthApplicationActions() {
5
6
  const t = useModuleT("oauthServer");
6
7
  const overlay = useOverlay();
@@ -8,7 +9,14 @@ export function useOAuthApplicationActions() {
8
9
  const toast = useToast();
9
10
  const { busy, run } = useAction();
10
11
  const { copy } = useCopyToClipboard();
12
+ const route = useRoute();
13
+ const router = useRouter();
14
+ const editing = ref(null);
11
15
  const refresh = () => refreshNuxtData(OAUTH_APPLICATIONS_KEY);
16
+ function setQuery(id) {
17
+ const { application: _previous, ...rest } = route.query;
18
+ return router.replace({ query: id ? { ...rest, application: id } : rest });
19
+ }
12
20
  function showCredentials(credentials) {
13
21
  overlay.create(OAuthCredentialsModal, { destroyOnClose: true, props: credentials }).open();
14
22
  }
@@ -30,19 +38,28 @@ export function useOAuthApplicationActions() {
30
38
  return saved;
31
39
  }
32
40
  async function edit(application) {
33
- const saved = await overlay.create(OAuthApplicationSlideover, {
34
- destroyOnClose: true,
35
- props: {
36
- application,
37
- save: async (input) => {
38
- const updated = await oauthApplicationsApi.update(application.id, input);
39
- await refresh();
40
- return updated;
41
+ if (editing.value === application.id) return void 0;
42
+ editing.value = application.id;
43
+ const path = route.path;
44
+ await setQuery(application.id);
45
+ try {
46
+ const saved = await overlay.create(OAuthApplicationSlideover, {
47
+ destroyOnClose: true,
48
+ props: {
49
+ application,
50
+ save: async (input) => {
51
+ const updated = await oauthApplicationsApi.update(application.id, input);
52
+ await refresh();
53
+ return updated;
54
+ }
41
55
  }
42
- }
43
- }).open();
44
- if (saved) toast.add({ title: t("admin.updated", "Application updated"), description: saved.name, color: "success", icon: "i-lucide-check" });
45
- return saved;
56
+ }).open();
57
+ if (saved) toast.add({ title: t("admin.updated", "Application updated"), description: saved.name, color: "success", icon: "i-lucide-check" });
58
+ return saved;
59
+ } finally {
60
+ editing.value = null;
61
+ if (route.path === path && route.query.application === application.id) await setQuery(null);
62
+ }
46
63
  }
47
64
  async function remove(application) {
48
65
  const confirmed = await confirm({
@@ -116,7 +133,7 @@ export function useOAuthApplicationActions() {
116
133
  void signOutEveryone(application);
117
134
  } }
118
135
  ], [
119
- { label: t("admin.delete", "Delete application"), icon: "i-lucide-trash", color: "error", onSelect: () => {
136
+ { label: t("admin.delete", "Delete application"), icon: "i-lucide-trash-2", color: "error", onSelect: () => {
120
137
  void remove(application);
121
138
  } }
122
139
  ]];
@@ -1,29 +1,50 @@
1
- import type { AdminApplicationDto, ApplicationInput, CreatedApplicationDto } from '../../../types.js';
1
+ import type { ComputedRef, MaybeRefOrGetter } from 'vue';
2
+ import type { AsyncData, NuxtError } from 'nuxt/app';
3
+ import type { AdminApplicationDto, AdminApplicationsPage, ApplicationInput, CreatedApplicationDto } from '../../../types.js';
4
+ type Application = AdminApplicationDto;
2
5
  /** The `useFetch` key of the admin list; `refreshNuxtData(OAUTH_APPLICATIONS_KEY)` reloads it from anywhere. */
3
6
  export declare const OAUTH_APPLICATIONS_KEY = "oauth-server:applications";
4
7
  /** The admin endpoints as plain calls (no refresh). Every call needs the host's `oauth:authorize` hook to allow the user. */
5
8
  export declare const oauthApplicationsApi: {
9
+ get: (id: string) => Promise<AdminApplicationDto>;
6
10
  create: (input: ApplicationInput) => Promise<CreatedApplicationDto>;
7
11
  update: (id: string, patch: Partial<ApplicationInput>) => Promise<AdminApplicationDto>;
8
- remove: (id: string) => Promise<unknown>;
12
+ /** 204: resolves with `null`. */
13
+ remove: (id: string) => Promise<null>;
9
14
  /** Returns the new client secret; the old one stops working. */
10
15
  rotateSecret: (id: string) => Promise<string>;
11
- revokeGrants: (id: string) => Promise<unknown>;
16
+ /** Signs everyone out of the application; resolves with the application. */
17
+ revokeGrants: (id: string) => Promise<AdminApplicationDto>;
12
18
  };
13
- /** Admin CRUD for applications. Every call needs the host's `oauth:authorize` hook to allow the user. */
14
- export declare function useOAuthApplications(): {
15
- applications: any;
16
- status: any;
17
- error: any;
18
- refresh: any;
19
+ /** The list query: `page`, `pageSize`, `q` (name or client id), `sort` (`createdAt`, `name`, `priority`) and `order`. */
20
+ export type OAuthApplicationsQuery = Record<string, string | number | undefined>;
21
+ type ApplicationsAsyncData = Awaited<AsyncData<AdminApplicationsPage | undefined, NuxtError | undefined>>;
22
+ /** What `useOAuthApplications` returns (and resolves with when awaited). */
23
+ export interface OAuthApplicationsState {
24
+ applications: ComputedRef<Application[]>;
25
+ total: ComputedRef<number>;
26
+ data: ApplicationsAsyncData['data'];
27
+ status: ApplicationsAsyncData['status'];
28
+ error: ApplicationsAsyncData['error'];
29
+ loading: ComputedRef<boolean>;
30
+ refreshing: ComputedRef<boolean>;
31
+ refresh: ApplicationsAsyncData['refresh'];
19
32
  create: (input: ApplicationInput) => Promise<CreatedApplicationDto>;
20
- update: (id: string, patch: Partial<ApplicationInput>) => Promise<AdminApplicationDto>;
21
- remove: (id: string) => Promise<void>;
33
+ update: (id: string, patch: Partial<ApplicationInput>) => Promise<Application>;
34
+ remove: (id: string) => Promise<null>;
22
35
  rotateSecret: (id: string) => Promise<string>;
23
- revokeGrants: (id: string) => Promise<void>;
24
- };
36
+ revokeGrants: (id: string) => Promise<Application>;
37
+ }
38
+ /**
39
+ * Admin CRUD for applications, with one page of the list. Awaitable: `await useOAuthApplications(query)` in a page
40
+ * renders the list on the server; pass `useTableQuery().query` to page, search and sort it. `applications` is `[]`
41
+ * until loaded and after an error: check `loading` and `error` first. Every call needs the host's `oauth:authorize`
42
+ * hook to allow the user.
43
+ */
44
+ export declare function useOAuthApplications(query?: MaybeRefOrGetter<OAuthApplicationsQuery>): OAuthApplicationsState & Promise<OAuthApplicationsState>;
25
45
  /**
26
46
  * The applications the signed-in user may sign in to. Awaitable: `await useMyApplications()` in a page renders them on
27
47
  * the server. `applications` is `[]` until loaded and after an error: check `loading` and `error` first.
28
48
  */
29
49
  export declare function useMyApplications(): any;
50
+ export {};
@@ -1,18 +1,27 @@
1
- const BASE = "/api/oauth-server";
1
+ import { oauthServerApi } from "../../utils/api.js";
2
+ import { $fetch, computed, useCachedFetch, useFetch, useUserSession, watch } from "#imports";
2
3
  export const OAUTH_APPLICATIONS_KEY = "oauth-server:applications";
3
4
  export const oauthApplicationsApi = {
4
- create: (input) => $fetch(`${BASE}/admin/applications`, { method: "POST", body: input }),
5
- update: (id, patch) => $fetch(`${BASE}/admin/applications/${id}`, { method: "PATCH", body: patch }),
6
- remove: (id) => $fetch(`${BASE}/admin/applications/${id}`, { method: "DELETE" }),
5
+ get: (id) => $fetch(oauthServerApi.admin.application(id)),
6
+ create: (input) => $fetch(oauthServerApi.admin.applications, { method: "POST", body: input }),
7
+ update: (id, patch) => $fetch(oauthServerApi.admin.application(id), { method: "PATCH", body: patch }),
8
+ /** 204: resolves with `null`. */
9
+ remove: async (id) => {
10
+ await $fetch(oauthServerApi.admin.application(id), { method: "DELETE" });
11
+ return null;
12
+ },
7
13
  /** Returns the new client secret; the old one stops working. */
8
- rotateSecret: async (id) => (await $fetch(`${BASE}/admin/applications/${id}/secret`, { method: "POST" })).clientSecret,
9
- revokeGrants: (id) => $fetch(`${BASE}/admin/applications/${id}/revoke`, { method: "POST" })
14
+ rotateSecret: async (id) => (await $fetch(oauthServerApi.admin.rotateSecret(id), { method: "POST" })).clientSecret,
15
+ /** Signs everyone out of the application; resolves with the application. */
16
+ revokeGrants: (id) => $fetch(oauthServerApi.admin.revoke(id), { method: "POST" })
10
17
  };
11
- export function useOAuthApplications() {
12
- const { data, status, error, refresh } = useFetch(`${BASE}/admin/applications`, {
13
- key: OAUTH_APPLICATIONS_KEY,
14
- default: () => []
15
- });
18
+ export function useOAuthApplications(query = {}) {
19
+ const fetched = useFetch(oauthServerApi.admin.applications, { key: OAUTH_APPLICATIONS_KEY, query });
20
+ const { data, status, error, refresh } = fetched;
21
+ const applications = computed(() => data.value?.items ?? []);
22
+ const total = computed(() => data.value?.total ?? 0);
23
+ const loading = computed(() => status.value === "pending" && !data.value);
24
+ const refreshing = computed(() => status.value === "pending" && !!data.value);
16
25
  async function create(input) {
17
26
  const created = await oauthApplicationsApi.create(input);
18
27
  await refresh();
@@ -26,6 +35,7 @@ export function useOAuthApplications() {
26
35
  async function remove(id) {
27
36
  await oauthApplicationsApi.remove(id);
28
37
  await refresh();
38
+ return null;
29
39
  }
30
40
  async function rotateSecret(id) {
31
41
  const clientSecret = await oauthApplicationsApi.rotateSecret(id);
@@ -33,14 +43,16 @@ export function useOAuthApplications() {
33
43
  return clientSecret;
34
44
  }
35
45
  async function revokeGrants(id) {
36
- await oauthApplicationsApi.revokeGrants(id);
46
+ const application = await oauthApplicationsApi.revokeGrants(id);
37
47
  await refresh();
48
+ return application;
38
49
  }
39
- return { applications: data, status, error, refresh, create, update, remove, rotateSecret, revokeGrants };
50
+ const api = { applications, total, data, status, error, loading, refreshing, refresh, create, update, remove, rotateSecret, revokeGrants };
51
+ return Object.assign(fetched.then(() => api), api);
40
52
  }
41
53
  export function useMyApplications() {
42
54
  const { loggedIn } = useUserSession();
43
- const fetched = useCachedFetch(`${BASE}/me/applications`, {
55
+ const fetched = useCachedFetch(oauthServerApi.me.applications, {
44
56
  key: "oauth-server:mine",
45
57
  ttl: 5 * 60 * 1e3,
46
58
  watch: false
@@ -1,15 +1,32 @@
1
1
  <script setup>
2
+ import { oauthApplicationsApi } from "../composables/useOAuthApplications";
3
+ import { computed, numericColumn, onMounted, useModuleT, useOAuthApplicationActions, useOAuthApplications, useRoute, useTableQuery, useTableSort, watch } from "#imports";
2
4
  defineOptions({ name: "OAuthAdminPage" });
3
5
  const t = useModuleT("oauthServer");
4
- const { applications, status, error } = useOAuthApplications();
6
+ const route = useRoute();
7
+ const { page, pageSize, search, sort: sortState, query, filtered, reset } = useTableQuery({
8
+ sort: { id: "createdAt", desc: true }
9
+ });
10
+ const sort = useTableSort(null, sortState);
11
+ const { sorting } = sort;
12
+ const { applications, total, data, status, error, loading, refreshing, refresh } = await useOAuthApplications(query);
5
13
  const actions = useOAuthApplicationActions();
6
14
  const forbidden = computed(() => error.value?.statusCode === 401 || error.value?.statusCode === 403);
15
+ const failed = computed(() => !!error.value && !forbidden.value && !data.value);
7
16
  const columns = computed(() => [
8
- { accessorKey: "name", header: t("admin.application", "Application") },
17
+ { accessorKey: "name", header: sort.header("name", t("admin.application", "Application")) },
9
18
  { id: "access", header: t("admin.access", "Access") },
10
- { id: "grants", header: t("admin.signedIn", "Signed in"), meta: numericColumn },
19
+ { id: "grants", accessorFn: (row) => row.activeGrants ?? 0, header: t("admin.signedIn", "Signed in"), meta: numericColumn },
11
20
  { id: "actions", header: "", meta: { class: { th: "w-0", td: "w-0" } } }
12
21
  ]);
22
+ async function openFromQuery() {
23
+ const id = route.query.application;
24
+ if (typeof id !== "string" || !id) return;
25
+ const application = applications.value.find((item) => item.id === id) ?? await oauthApplicationsApi.get(id).catch(() => void 0);
26
+ if (application) void actions.edit(application);
27
+ }
28
+ onMounted(openFromQuery);
29
+ watch(() => route.query.application, openFromQuery);
13
30
  </script>
14
31
 
15
32
  <template>
@@ -36,76 +53,111 @@ const columns = computed(() => [
36
53
  :title="t('admin.forbiddenTitle', 'You are not allowed to manage OAuth applications')"
37
54
  :description="t('admin.forbiddenDescription', 'Ask an administrator for access.')"
38
55
  />
39
- <TableCard
40
- v-else
41
- :loading="status === 'pending' && !applications.length"
42
- :refreshing="status === 'pending' && !!applications.length"
43
- >
44
- <UTable
45
- :data="applications"
46
- :columns="columns"
47
- :ui="tableUi()"
48
- @select="(_event, row2) => actions.edit(row2.original)"
56
+ <UEmpty
57
+ v-else-if="failed"
58
+ icon="i-lucide-circle-alert"
59
+ :title="t('admin.loadFailed', 'OAuth applications could not be loaded')"
60
+ :description="errorMessage(error, '')"
61
+ :actions="[{ label: t('admin.tryAgain', 'Try again'), icon: 'i-lucide-rotate-ccw', color: 'neutral', variant: 'outline', onClick: () => refresh() }]"
62
+ />
63
+ <template v-else>
64
+ <PageToolbar>
65
+ <UInput
66
+ v-model="search"
67
+ class="w-full max-w-sm"
68
+ icon="i-lucide-search"
69
+ :loading="status === 'pending'"
70
+ :placeholder="t('admin.search', 'Search name or client ID...')"
71
+ />
72
+ </PageToolbar>
73
+
74
+ <TableCard
75
+ :loading="loading"
76
+ :refreshing="refreshing"
49
77
  >
50
- <template #name-cell="{ row }">
51
- <TableIdentity
52
- :title="row.original.name"
53
- :description="row.original.websiteUrl"
54
- :avatar="{ icon: row.original.icon || 'i-lucide-globe' }"
55
- >
56
- <template #badges>
78
+ <UTable
79
+ v-model:sorting="sorting"
80
+ :data="applications"
81
+ :columns="columns"
82
+ :sorting-options="{ manualSorting: true }"
83
+ :ui="tableUi()"
84
+ @select="(_event, row2) => actions.edit(row2.original)"
85
+ >
86
+ <template #name-cell="{ row }">
87
+ <TableIdentity
88
+ :title="row.original.name"
89
+ :description="row.original.websiteUrl"
90
+ :avatar="{ icon: row.original.icon || 'i-lucide-globe' }"
91
+ >
92
+ <template #badges>
93
+ <UBadge
94
+ v-if="row.original.clientType === 'public'"
95
+ color="info"
96
+ variant="subtle"
97
+ size="sm"
98
+ :label="t('admin.public', 'Public')"
99
+ />
100
+ <UBadge
101
+ v-if="!row.original.isActive"
102
+ color="neutral"
103
+ variant="subtle"
104
+ size="sm"
105
+ :label="t('admin.disabled', 'Disabled')"
106
+ />
107
+ </template>
108
+ </TableIdentity>
109
+ </template>
110
+ <template #access-cell="{ row }">
111
+ <div class="flex flex-wrap gap-1">
57
112
  <UBadge
58
- v-if="row.original.clientType === 'public'"
59
- color="info"
113
+ v-for="role in row.original.allowedRoles"
114
+ :key="role"
60
115
  variant="subtle"
61
- size="sm"
62
- :label="t('admin.public', 'Public')"
116
+ :label="role"
63
117
  />
64
118
  <UBadge
65
- v-if="!row.original.isActive"
119
+ v-if="!row.original.allowedRoles.length"
66
120
  color="neutral"
67
121
  variant="subtle"
68
- size="sm"
69
- :label="t('admin.disabled', 'Disabled')"
122
+ :label="t('admin.everyone', 'Every signed-in user')"
70
123
  />
71
- </template>
72
- </TableIdentity>
73
- </template>
74
- <template #access-cell="{ row }">
75
- <div class="flex flex-wrap gap-1">
76
- <UBadge
77
- v-for="role in row.original.allowedRoles"
78
- :key="role"
79
- variant="subtle"
80
- :label="role"
124
+ </div>
125
+ </template>
126
+ <template #grants-cell="{ row }">
127
+ {{ row.original.activeGrants ?? 0 }}
128
+ </template>
129
+ <template #actions-cell="{ row }">
130
+ <RowMenu
131
+ :items="actions.menu(row.original)"
132
+ :subject="row.original.name"
81
133
  />
82
- <UBadge
83
- v-if="!row.original.allowedRoles.length"
84
- color="neutral"
85
- variant="subtle"
86
- :label="t('admin.everyone', 'Every signed-in user')"
134
+ </template>
135
+ <template #empty>
136
+ <UEmpty
137
+ v-if="filtered"
138
+ variant="naked"
139
+ icon="i-lucide-search"
140
+ :title="t('admin.noMatches', 'No applications match')"
141
+ :actions="[{ label: t('admin.clearSearch', 'Clear search'), color: 'neutral', variant: 'outline', onClick: reset }]"
87
142
  />
88
- </div>
89
- </template>
90
- <template #grants-cell="{ row }">
91
- {{ row.original.activeGrants ?? 0 }}
92
- </template>
93
- <template #actions-cell="{ row }">
94
- <RowMenu
95
- :items="actions.menu(row.original)"
96
- :subject="row.original.name"
97
- />
98
- </template>
99
- <template #empty>
100
- <UEmpty
101
- variant="naked"
102
- icon="i-lucide-app-window"
103
- :title="t('admin.emptyTitle', 'No applications yet')"
104
- :description="t('admin.emptyDescription', 'Add an application to let users sign in to it with their account.')"
105
- :actions="[{ label: t('admin.new', 'Add application'), icon: 'i-lucide-plus', onClick: () => actions.create() }]"
143
+ <UEmpty
144
+ v-else
145
+ variant="naked"
146
+ icon="i-lucide-app-window"
147
+ :title="t('admin.emptyTitle', 'No applications yet')"
148
+ :description="t('admin.emptyDescription', 'Add an application to let users sign in to it with their account.')"
149
+ :actions="[{ label: t('admin.new', 'Add application'), icon: 'i-lucide-plus', onClick: () => actions.create() }]"
150
+ />
151
+ </template>
152
+ </UTable>
153
+ <template #footer>
154
+ <TablePagination
155
+ v-model:page="page"
156
+ v-model:page-size="pageSize"
157
+ :total="total"
106
158
  />
107
159
  </template>
108
- </UTable>
109
- </TableCard>
160
+ </TableCard>
161
+ </template>
110
162
  </div>
111
163
  </template>