@better-auth-ui/react 1.6.6 → 1.6.8
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/dist/index.d.ts +3 -0
- package/dist/index.js +31 -28
- package/dist/lib/auth-client.d.ts +4 -0
- package/dist/mutations/api-key/create-api-key-mutation.d.ts +65 -0
- package/dist/mutations/api-key/create-api-key-mutation.js +29 -0
- package/dist/mutations/api-key/delete-api-key-mutation.d.ts +21 -0
- package/dist/mutations/api-key/delete-api-key-mutation.js +29 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +16 -16
- package/dist/mutations/username/sign-in-username-mutation.d.ts +4 -0
- package/dist/queries/api-key/list-api-keys-query.d.ts +64 -0
- package/dist/queries/api-key/list-api-keys-query.js +31 -0
- package/package.json +7 -5
- package/src/index.ts +3 -0
- package/src/lib/auth-client.ts +5 -0
- package/src/mutations/api-key/create-api-key-mutation.ts +64 -0
- package/src/mutations/api-key/delete-api-key-mutation.ts +62 -0
- package/src/queries/api-key/list-api-keys-query.ts +115 -0
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export * from './hooks/use-auth-query';
|
|
|
10
10
|
export type * from './lib/auth-client';
|
|
11
11
|
export * from './lib/auth-plugin';
|
|
12
12
|
export * from './lib/provider-icons';
|
|
13
|
+
export * from './mutations/api-key/create-api-key-mutation';
|
|
14
|
+
export * from './mutations/api-key/delete-api-key-mutation';
|
|
13
15
|
export * from './mutations/auth/request-password-reset-mutation';
|
|
14
16
|
export * from './mutations/auth/reset-password-mutation';
|
|
15
17
|
export * from './mutations/auth/send-verification-email-mutation';
|
|
@@ -33,6 +35,7 @@ export * from './mutations/settings/unlink-account-mutation';
|
|
|
33
35
|
export * from './mutations/settings/update-user-mutation';
|
|
34
36
|
export * from './mutations/username/is-username-available-mutation';
|
|
35
37
|
export * from './mutations/username/sign-in-username-mutation';
|
|
38
|
+
export * from './queries/api-key/list-api-keys-query';
|
|
36
39
|
export * from './queries/auth/session-query';
|
|
37
40
|
export * from './queries/auth-query-options';
|
|
38
41
|
export * from './queries/multi-session/list-device-sessions-query';
|
package/dist/index.js
CHANGED
|
@@ -47,31 +47,34 @@ import { useAuthPlugin as Z } from "./hooks/use-auth-plugin.js";
|
|
|
47
47
|
import { authQueryOptions as Q } from "./queries/auth-query-options.js";
|
|
48
48
|
import { useAuthQuery as $ } from "./hooks/use-auth-query.js";
|
|
49
49
|
import { providerIcons as ee } from "./lib/provider-icons.js";
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
import {
|
|
68
|
-
import {
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
import {
|
|
76
|
-
import {
|
|
77
|
-
|
|
50
|
+
import { ensureListApiKeys as te, fetchListApiKeys as ne, listApiKeysOptions as re, prefetchListApiKeys as ie, useListApiKeys as ae } from "./queries/api-key/list-api-keys-query.js";
|
|
51
|
+
import { createApiKeyOptions as oe, useCreateApiKey as se } from "./mutations/api-key/create-api-key-mutation.js";
|
|
52
|
+
import { deleteApiKeyOptions as ce, useDeleteApiKey as le } from "./mutations/api-key/delete-api-key-mutation.js";
|
|
53
|
+
import { requestPasswordResetOptions as ue, useRequestPasswordReset as de } from "./mutations/auth/request-password-reset-mutation.js";
|
|
54
|
+
import { resetPasswordOptions as fe, useResetPassword as pe } from "./mutations/auth/reset-password-mutation.js";
|
|
55
|
+
import { sendVerificationEmailOptions as me, useSendVerificationEmail as he } from "./mutations/auth/send-verification-email-mutation.js";
|
|
56
|
+
import { signInEmailOptions as ge, useSignInEmail as _e } from "./mutations/auth/sign-in-email-mutation.js";
|
|
57
|
+
import { signInSocialOptions as ve, useSignInSocial as ye } from "./mutations/auth/sign-in-social-mutation.js";
|
|
58
|
+
import { signOutOptions as be, useSignOut as xe } from "./mutations/auth/sign-out-mutation.js";
|
|
59
|
+
import { signUpEmailOptions as Se, useSignUpEmail as Ce } from "./mutations/auth/sign-up-email-mutation.js";
|
|
60
|
+
import { signInMagicLinkOptions as we, useSignInMagicLink as Te } from "./mutations/magic-link/sign-in-magic-link-mutation.js";
|
|
61
|
+
import { ensureListDeviceSessions as Ee, fetchListDeviceSessions as De, listDeviceSessionsOptions as Oe, prefetchListDeviceSessions as ke, useListDeviceSessions as Ae } from "./queries/multi-session/list-device-sessions-query.js";
|
|
62
|
+
import { revokeMultiSessionOptions as je, useRevokeMultiSession as Me } from "./mutations/multi-session/revoke-multi-session-mutation.js";
|
|
63
|
+
import { setActiveSessionOptions as Ne, useSetActiveSession as Pe } from "./mutations/multi-session/set-active-session-mutation.js";
|
|
64
|
+
import { ensureListPasskeys as Fe, fetchListPasskeys as Ie, listPasskeysOptions as Le, prefetchListPasskeys as Re, useListPasskeys as ze } from "./queries/passkey/list-passkeys-query.js";
|
|
65
|
+
import { addPasskeyOptions as Be, useAddPasskey as Ve } from "./mutations/passkey/add-passkey-mutation.js";
|
|
66
|
+
import { deletePasskeyOptions as He, useDeletePasskey as Ue } from "./mutations/passkey/delete-passkey-mutation.js";
|
|
67
|
+
import { signInPasskeyOptions as We, useSignInPasskey as Ge } from "./mutations/passkey/sign-in-passkey-mutation.js";
|
|
68
|
+
import { changeEmailOptions as Ke, useChangeEmail as qe } from "./mutations/settings/change-email-mutation.js";
|
|
69
|
+
import { changePasswordOptions as Je, useChangePassword as Ye } from "./mutations/settings/change-password-mutation.js";
|
|
70
|
+
import { deleteUserOptions as Xe, useDeleteUser as Ze } from "./mutations/settings/delete-user-mutation.js";
|
|
71
|
+
import { linkSocialOptions as Qe, useLinkSocial as $e } from "./mutations/settings/link-social-mutation.js";
|
|
72
|
+
import { ensureListSessions as et, fetchListSessions as tt, listSessionsOptions as nt, prefetchListSessions as rt, useListSessions as it } from "./queries/settings/list-sessions-query.js";
|
|
73
|
+
import { revokeSessionOptions as at, useRevokeSession as ot } from "./mutations/settings/revoke-session-mutation.js";
|
|
74
|
+
import { ensureListAccounts as st, fetchListAccounts as ct, listAccountsOptions as lt, prefetchListAccounts as ut, useListAccounts as dt } from "./queries/settings/list-accounts-query.js";
|
|
75
|
+
import { unlinkAccountOptions as ft, useUnlinkAccount as pt } from "./mutations/settings/unlink-account-mutation.js";
|
|
76
|
+
import { updateUserOptions as mt, useUpdateUser as ht } from "./mutations/settings/update-user-mutation.js";
|
|
77
|
+
import { isUsernameAvailableOptions as gt, useIsUsernameAvailable as _t } from "./mutations/username/is-username-available-mutation.js";
|
|
78
|
+
import { signInUsernameOptions as vt, useSignInUsername as yt } from "./mutations/username/sign-in-username-mutation.js";
|
|
79
|
+
import { accountInfoOptions as bt, ensureAccountInfo as xt, fetchAccountInfo as St, prefetchAccountInfo as Ct, useAccountInfo as wt } from "./queries/settings/account-info-query.js";
|
|
80
|
+
export { i as Apple, a as Atlassian, n as AuthProvider, o as Cognito, s as Discord, c as Dropbox, l as Facebook, e as FetchOptionsProvider, u as Figma, d as GitHub, f as GitLab, p as Google, m as HuggingFace, h as Kakao, g as Kick, _ as Line, v as Linear, y as LinkedIn, b as Microsoft, x as Naver, S as Notion, w as PayPal, C as Paybin, T as Polar, E as Railway, D as Reddit, O as Roblox, k as Salesforce, A as Slack, j as Spotify, z as ThemePreviewDark, B as ThemePreviewLight, V as ThemePreviewSystem, M as TikTok, N as Twitch, F as VK, P as Vercel, I as WeChat, L as X, R as Zoom, bt as accountInfoOptions, Be as addPasskeyOptions, Y as authMutationOptions, Q as authQueryOptions, Ke as changeEmailOptions, Je as changePasswordOptions, oe as createApiKeyOptions, ce as deleteApiKeyOptions, He as deletePasskeyOptions, Xe as deleteUserOptions, xt as ensureAccountInfo, st as ensureListAccounts, te as ensureListApiKeys, Ee as ensureListDeviceSessions, Fe as ensureListPasskeys, et as ensureListSessions, H as ensureSession, St as fetchAccountInfo, ct as fetchListAccounts, ne as fetchListApiKeys, De as fetchListDeviceSessions, Ie as fetchListPasskeys, tt as fetchListSessions, U as fetchSession, gt as isUsernameAvailableOptions, Qe as linkSocialOptions, lt as listAccountsOptions, re as listApiKeysOptions, Oe as listDeviceSessionsOptions, Le as listPasskeysOptions, nt as listSessionsOptions, Ct as prefetchAccountInfo, ut as prefetchListAccounts, ie as prefetchListApiKeys, ke as prefetchListDeviceSessions, Re as prefetchListPasskeys, rt as prefetchListSessions, W as prefetchSession, ee as providerIcons, ue as requestPasswordResetOptions, fe as resetPasswordOptions, je as revokeMultiSessionOptions, at as revokeSessionOptions, me as sendVerificationEmailOptions, G as sessionOptions, Ne as setActiveSessionOptions, ge as signInEmailOptions, we as signInMagicLinkOptions, We as signInPasskeyOptions, ve as signInSocialOptions, vt as signInUsernameOptions, be as signOutOptions, Se as signUpEmailOptions, ft as unlinkAccountOptions, mt as updateUserOptions, wt as useAccountInfo, Ve as useAddPasskey, r as useAuth, X as useAuthMutation, Z as useAuthPlugin, $ as useAuthQuery, q as useAuthenticate, qe as useChangeEmail, Ye as useChangePassword, se as useCreateApiKey, le as useDeleteApiKey, Ue as useDeletePasskey, Ze as useDeleteUser, t as useFetchOptions, _t as useIsUsernameAvailable, $e as useLinkSocial, dt as useListAccounts, ae as useListApiKeys, Ae as useListDeviceSessions, ze as useListPasskeys, it as useListSessions, de as useRequestPasswordReset, pe as useResetPassword, Me as useRevokeMultiSession, ot as useRevokeSession, he as useSendVerificationEmail, K as useSession, Pe as useSetActiveSession, _e as useSignInEmail, Te as useSignInMagicLink, Ge as useSignInPasskey, ye as useSignInSocial, yt as useSignInUsername, xe as useSignOut, Ce as useSignUpEmail, pt as useUnlinkAccount, ht as useUpdateUser, J as useUser };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { apiKeyClient } from '@better-auth/api-key/client';
|
|
1
2
|
import { passkeyClient } from '@better-auth/passkey/client';
|
|
2
3
|
import { magicLinkClient, multiSessionClient, usernameClient } from 'better-auth/client/plugins';
|
|
3
4
|
import { createAuthClient } from 'better-auth/react';
|
|
@@ -11,6 +12,9 @@ export type MultiSessionAuthClient = ReturnType<typeof createAuthClient<{
|
|
|
11
12
|
export type PasskeyAuthClient = ReturnType<typeof createAuthClient<{
|
|
12
13
|
plugins: [ReturnType<typeof passkeyClient>];
|
|
13
14
|
}>>;
|
|
15
|
+
export type ApiKeyAuthClient = ReturnType<typeof createAuthClient<{
|
|
16
|
+
plugins: [ReturnType<typeof apiKeyClient>];
|
|
17
|
+
}>>;
|
|
14
18
|
export type UsernameAuthClient = ReturnType<typeof createAuthClient<{
|
|
15
19
|
plugins: [ReturnType<typeof usernameClient>];
|
|
16
20
|
}>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
2
|
+
import { ApiKeyAuthClient } from '../../lib/auth-client';
|
|
3
|
+
export type CreateApiKeyParams<TAuthClient extends ApiKeyAuthClient> = Parameters<TAuthClient["apiKey"]["create"]>[0];
|
|
4
|
+
export type CreateApiKeyOptions<TAuthClient extends ApiKeyAuthClient> = Omit<ReturnType<typeof createApiKeyOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
5
|
+
/**
|
|
6
|
+
* Mutation options factory for creating an API key.
|
|
7
|
+
*
|
|
8
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createApiKeyOptions<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient): import('@tanstack/react-query').WithRequired<import('@tanstack/react-query').UseMutationOptions<{
|
|
11
|
+
key: string;
|
|
12
|
+
metadata: any;
|
|
13
|
+
permissions: any;
|
|
14
|
+
id: string;
|
|
15
|
+
configId: string;
|
|
16
|
+
name: string | null;
|
|
17
|
+
start: string | null;
|
|
18
|
+
prefix: string | null;
|
|
19
|
+
referenceId: string;
|
|
20
|
+
refillInterval: number | null;
|
|
21
|
+
refillAmount: number | null;
|
|
22
|
+
lastRefillAt: Date | null;
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
rateLimitEnabled: boolean;
|
|
25
|
+
rateLimitTimeWindow: number | null;
|
|
26
|
+
rateLimitMax: number | null;
|
|
27
|
+
requestCount: number;
|
|
28
|
+
remaining: number | null;
|
|
29
|
+
lastRequest: Date | null;
|
|
30
|
+
expiresAt: Date | null;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
}, BetterFetchError, CreateApiKeyParams<TAuthClient>, unknown>, "mutationKey">;
|
|
34
|
+
/**
|
|
35
|
+
* Create a mutation for creating an API key.
|
|
36
|
+
*
|
|
37
|
+
* Refetches the user's API key list on success unless disabled via options.
|
|
38
|
+
*
|
|
39
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
40
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useCreateApiKey<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, options?: CreateApiKeyOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<{
|
|
43
|
+
key: string;
|
|
44
|
+
metadata: any;
|
|
45
|
+
permissions: any;
|
|
46
|
+
id: string;
|
|
47
|
+
configId: string;
|
|
48
|
+
name: string | null;
|
|
49
|
+
start: string | null;
|
|
50
|
+
prefix: string | null;
|
|
51
|
+
referenceId: string;
|
|
52
|
+
refillInterval: number | null;
|
|
53
|
+
refillAmount: number | null;
|
|
54
|
+
lastRefillAt: Date | null;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
rateLimitEnabled: boolean;
|
|
57
|
+
rateLimitTimeWindow: number | null;
|
|
58
|
+
rateLimitMax: number | null;
|
|
59
|
+
requestCount: number;
|
|
60
|
+
remaining: number | null;
|
|
61
|
+
lastRequest: Date | null;
|
|
62
|
+
expiresAt: Date | null;
|
|
63
|
+
createdAt: Date;
|
|
64
|
+
updatedAt: Date;
|
|
65
|
+
}, BetterFetchError, CreateApiKeyParams<TAuthClient>, unknown>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useListApiKeys as e } from "../../queries/api-key/list-api-keys-query.js";
|
|
2
|
+
import { mutationOptions as t, useMutation as n } from "@tanstack/react-query";
|
|
3
|
+
import { apiKeyMutationKeys as r } from "@better-auth-ui/core/plugins";
|
|
4
|
+
//#region src/mutations/api-key/create-api-key-mutation.ts
|
|
5
|
+
function i(e) {
|
|
6
|
+
let n = r.createApiKey;
|
|
7
|
+
return t({
|
|
8
|
+
mutationKey: n,
|
|
9
|
+
mutationFn: (t) => e.apiKey.create({
|
|
10
|
+
...t,
|
|
11
|
+
fetchOptions: {
|
|
12
|
+
...t?.fetchOptions,
|
|
13
|
+
throw: !0
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function a(t, r) {
|
|
19
|
+
let { refetch: a } = e(t, { refetchOnMount: !1 });
|
|
20
|
+
return n({
|
|
21
|
+
...i(t),
|
|
22
|
+
...r,
|
|
23
|
+
onSuccess: async (...e) => {
|
|
24
|
+
await a(), await r?.onSuccess?.(...e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { i as createApiKeyOptions, a as useCreateApiKey };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
2
|
+
import { ApiKeyAuthClient } from '../../lib/auth-client';
|
|
3
|
+
export type DeleteApiKeyParams<TAuthClient extends ApiKeyAuthClient> = Parameters<TAuthClient["apiKey"]["delete"]>[0];
|
|
4
|
+
export type DeleteApiKeyOptions<TAuthClient extends ApiKeyAuthClient> = Omit<ReturnType<typeof deleteApiKeyOptions<TAuthClient>>, "mutationKey" | "mutationFn">;
|
|
5
|
+
/**
|
|
6
|
+
* Mutation options factory for deleting an API key.
|
|
7
|
+
*
|
|
8
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deleteApiKeyOptions<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient): import('@tanstack/react-query').WithRequired<import('@tanstack/react-query').UseMutationOptions<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
}, BetterFetchError, DeleteApiKeyParams<TAuthClient>, unknown>, "mutationKey">;
|
|
13
|
+
/**
|
|
14
|
+
* Create a mutation for deleting an API key.
|
|
15
|
+
*
|
|
16
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
17
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDeleteApiKey<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, options?: DeleteApiKeyOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
}, BetterFetchError, DeleteApiKeyParams<TAuthClient>, unknown>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useListApiKeys as e } from "../../queries/api-key/list-api-keys-query.js";
|
|
2
|
+
import { mutationOptions as t, useMutation as n } from "@tanstack/react-query";
|
|
3
|
+
import { apiKeyMutationKeys as r } from "@better-auth-ui/core/plugins";
|
|
4
|
+
//#region src/mutations/api-key/delete-api-key-mutation.ts
|
|
5
|
+
function i(e) {
|
|
6
|
+
let n = r.deleteApiKey;
|
|
7
|
+
return t({
|
|
8
|
+
mutationKey: n,
|
|
9
|
+
mutationFn: (t) => e.apiKey.delete({
|
|
10
|
+
...t,
|
|
11
|
+
fetchOptions: {
|
|
12
|
+
...t?.fetchOptions,
|
|
13
|
+
throw: !0
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function a(t, r) {
|
|
19
|
+
let { refetch: a } = e(t, { refetchOnMount: !1 });
|
|
20
|
+
return n({
|
|
21
|
+
...i(t),
|
|
22
|
+
...r,
|
|
23
|
+
onSuccess: async (...e) => {
|
|
24
|
+
await a(), await r?.onSuccess?.(...e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { i as deleteApiKeyOptions, a as useDeleteApiKey };
|
|
@@ -20,6 +20,14 @@ export declare function signInPasskeyOptions<TAuthClient extends PasskeyAuthClie
|
|
|
20
20
|
user: import('better-auth').User;
|
|
21
21
|
};
|
|
22
22
|
error: null;
|
|
23
|
+
} | {
|
|
24
|
+
data: null;
|
|
25
|
+
error: {
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
status: number;
|
|
29
|
+
statusText: string;
|
|
30
|
+
};
|
|
23
31
|
} | {
|
|
24
32
|
webauthn: {
|
|
25
33
|
response: import('@better-auth/passkey/client').AuthenticationResponseJSON;
|
|
@@ -41,14 +49,6 @@ export declare function signInPasskeyOptions<TAuthClient extends PasskeyAuthClie
|
|
|
41
49
|
user: import('better-auth').User;
|
|
42
50
|
};
|
|
43
51
|
error: null;
|
|
44
|
-
} | {
|
|
45
|
-
data: null;
|
|
46
|
-
error: {
|
|
47
|
-
code: string;
|
|
48
|
-
message: string;
|
|
49
|
-
status: number;
|
|
50
|
-
statusText: string;
|
|
51
|
-
};
|
|
52
52
|
}, BetterFetchError, void | SignInPasskeyParams<TAuthClient> | undefined, unknown>, "mutationKey">;
|
|
53
53
|
/**
|
|
54
54
|
* Create a mutation for passkey sign-in.
|
|
@@ -73,6 +73,14 @@ export declare function useSignInPasskey<TAuthClient extends PasskeyAuthClient>(
|
|
|
73
73
|
user: import('better-auth').User;
|
|
74
74
|
};
|
|
75
75
|
error: null;
|
|
76
|
+
} | {
|
|
77
|
+
data: null;
|
|
78
|
+
error: {
|
|
79
|
+
code: string;
|
|
80
|
+
message: string;
|
|
81
|
+
status: number;
|
|
82
|
+
statusText: string;
|
|
83
|
+
};
|
|
76
84
|
} | {
|
|
77
85
|
webauthn: {
|
|
78
86
|
response: import('@better-auth/passkey/client').AuthenticationResponseJSON;
|
|
@@ -94,12 +102,4 @@ export declare function useSignInPasskey<TAuthClient extends PasskeyAuthClient>(
|
|
|
94
102
|
user: import('better-auth').User;
|
|
95
103
|
};
|
|
96
104
|
error: null;
|
|
97
|
-
} | {
|
|
98
|
-
data: null;
|
|
99
|
-
error: {
|
|
100
|
-
code: string;
|
|
101
|
-
message: string;
|
|
102
|
-
status: number;
|
|
103
|
-
statusText: string;
|
|
104
|
-
};
|
|
105
105
|
}, BetterFetchError, void | SignInPasskeyParams<TAuthClient> | undefined, unknown>;
|
|
@@ -8,7 +8,9 @@ export type SignInUsernameOptions<TAuthClient extends UsernameAuthClient> = Omit
|
|
|
8
8
|
* @param authClient - The Better Auth client.
|
|
9
9
|
*/
|
|
10
10
|
export declare function signInUsernameOptions<TAuthClient extends UsernameAuthClient>(authClient: TAuthClient): import('@tanstack/react-query').WithRequired<import('@tanstack/react-query').UseMutationOptions<Omit<{
|
|
11
|
+
redirect: boolean;
|
|
11
12
|
token: string;
|
|
13
|
+
url: string | undefined;
|
|
12
14
|
user: {
|
|
13
15
|
id: string;
|
|
14
16
|
createdAt: Date;
|
|
@@ -46,7 +48,9 @@ export declare function signInUsernameOptions<TAuthClient extends UsernameAuthCl
|
|
|
46
48
|
* @param options - React Query options forwarded to `useMutation`.
|
|
47
49
|
*/
|
|
48
50
|
export declare function useSignInUsername<TAuthClient extends UsernameAuthClient>(authClient: TAuthClient, options?: SignInUsernameOptions<TAuthClient>): import('@tanstack/react-query').UseMutationResult<Omit<{
|
|
51
|
+
redirect: boolean;
|
|
49
52
|
token: string;
|
|
53
|
+
url: string | undefined;
|
|
50
54
|
user: {
|
|
51
55
|
id: string;
|
|
52
56
|
createdAt: Date;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { ApiKeyAuthClient, InferData } from '../../lib/auth-client';
|
|
4
|
+
export type ListApiKeysData<TAuthClient extends ApiKeyAuthClient> = InferData<TAuthClient["apiKey"]["list"]>;
|
|
5
|
+
export type ListApiKeysParams<TAuthClient extends ApiKeyAuthClient> = Parameters<TAuthClient["apiKey"]["list"]>[0];
|
|
6
|
+
export type ListedApiKey<TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient> = NonNullable<ListApiKeysData<TAuthClient>>["apiKeys"][number];
|
|
7
|
+
export type ListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = Omit<ReturnType<typeof listApiKeysOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for the current user's API keys.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.apiKey.list`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListApiKeysParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["apiKey"]["list"]>, BetterFetchError, InferData<TAuthClient["apiKey"]["list"]>, readonly ["auth", "user", string | undefined, "listApiKeys", {
|
|
16
|
+
configId?: string | undefined;
|
|
17
|
+
organizationId?: string | undefined;
|
|
18
|
+
limit?: unknown;
|
|
19
|
+
offset?: unknown;
|
|
20
|
+
sortBy?: string | undefined;
|
|
21
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
22
|
+
} | null]>, "queryFn"> & {
|
|
23
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["apiKey"]["list"]>, readonly ["auth", "user", string | undefined, "listApiKeys", {
|
|
24
|
+
configId?: string | undefined;
|
|
25
|
+
organizationId?: string | undefined;
|
|
26
|
+
limit?: unknown;
|
|
27
|
+
offset?: unknown;
|
|
28
|
+
sortBy?: string | undefined;
|
|
29
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
30
|
+
} | null], never> | undefined;
|
|
31
|
+
} & {
|
|
32
|
+
queryKey: readonly ["auth", "user", string | undefined, "listApiKeys", {
|
|
33
|
+
configId?: string | undefined;
|
|
34
|
+
organizationId?: string | undefined;
|
|
35
|
+
limit?: unknown;
|
|
36
|
+
offset?: unknown;
|
|
37
|
+
sortBy?: string | undefined;
|
|
38
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
39
|
+
} | null] & {
|
|
40
|
+
[dataTagSymbol]: InferData<TAuthClient["apiKey"]["list"]>;
|
|
41
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
42
|
+
};
|
|
43
|
+
}) & {
|
|
44
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "listApiKeys", {
|
|
45
|
+
configId?: string | undefined;
|
|
46
|
+
organizationId?: string | undefined;
|
|
47
|
+
limit?: unknown;
|
|
48
|
+
offset?: unknown;
|
|
49
|
+
sortBy?: string | undefined;
|
|
50
|
+
sortDirection?: "asc" | "desc" | undefined;
|
|
51
|
+
} | null], InferData<TAuthClient["apiKey"]["list"]>, BetterFetchError>;
|
|
52
|
+
};
|
|
53
|
+
export declare const ensureListApiKeys: <TAuthClient extends ApiKeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListApiKeysParams<TAuthClient>) => Promise<InferData<TAuthClient["apiKey"]["list"]>>;
|
|
54
|
+
export declare const prefetchListApiKeys: <TAuthClient extends ApiKeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListApiKeysParams<TAuthClient>) => Promise<void>;
|
|
55
|
+
export declare const fetchListApiKeys: <TAuthClient extends ApiKeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListApiKeysParams<TAuthClient>) => Promise<InferData<TAuthClient["apiKey"]["list"]>>;
|
|
56
|
+
export type UseListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = ListApiKeysOptions<TAuthClient> & ListApiKeysParams<TAuthClient>;
|
|
57
|
+
/**
|
|
58
|
+
* Subscribe to the current user's API keys via TanStack Query.
|
|
59
|
+
*
|
|
60
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
61
|
+
* @param options - `apiKey.list` params merged with `useQuery` options.
|
|
62
|
+
* @param queryClient - Optional custom `QueryClient`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useListApiKeys<TAuthClient extends ApiKeyAuthClient>(authClient: TAuthClient, options?: UseListApiKeysOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["apiKey"]["list"]>>, BetterFetchError>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useSession as e } from "../auth/session-query.js";
|
|
2
|
+
import { authQueryKeys as t } from "@better-auth-ui/core";
|
|
3
|
+
import { queryOptions as n, skipToken as r, useQuery as i } from "@tanstack/react-query";
|
|
4
|
+
//#region src/queries/api-key/list-api-keys-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.listApiKeys(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.apiKey.list({
|
|
9
|
+
...i,
|
|
10
|
+
fetchOptions: {
|
|
11
|
+
...i?.fetchOptions,
|
|
12
|
+
signal: t,
|
|
13
|
+
throw: !0
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
var o = (e, t, n, r) => e.ensureQueryData(a(t, n, r)), s = (e, t, n, r) => e.prefetchQuery(a(t, n, r)), c = (e, t, n, r) => e.fetchQuery(a(t, n, r));
|
|
19
|
+
function l(t, n = {}, o) {
|
|
20
|
+
let { data: s } = e(t, void 0, o), c = s?.user.id, { query: l, fetchOptions: u, ...d } = n, f = a(t, c, {
|
|
21
|
+
query: l,
|
|
22
|
+
fetchOptions: u
|
|
23
|
+
});
|
|
24
|
+
return i({
|
|
25
|
+
...d,
|
|
26
|
+
...f,
|
|
27
|
+
queryFn: c ? f.queryFn : r
|
|
28
|
+
}, o);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { o as ensureListApiKeys, c as fetchListApiKeys, a as listApiKeysOptions, s as prefetchListApiKeys, l as useListApiKeys };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth-ui/react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@better-auth/
|
|
36
|
+
"@better-auth/api-key": "^1.6.9",
|
|
37
|
+
"@better-auth/passkey": "^1.6.10",
|
|
37
38
|
"@react-email/components": "^1.0.12",
|
|
38
39
|
"@react-email/preview-server": "^5.2.10",
|
|
39
40
|
"@tanstack/react-query": "^5.100.9",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"@types/react": "^19.2.14",
|
|
43
44
|
"@vitejs/plugin-react": "^6.0.1",
|
|
44
45
|
"@vitest/browser-playwright": "^4.1.5",
|
|
45
|
-
"better-auth": "^1.6.
|
|
46
|
+
"better-auth": "^1.6.10",
|
|
46
47
|
"clsx": "^2.1.1",
|
|
47
48
|
"playwright": "^1.59.1",
|
|
48
49
|
"react": "^19.2.6",
|
|
@@ -55,10 +56,11 @@
|
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"@better-auth-ui/core": "*",
|
|
58
|
-
"@better-auth/
|
|
59
|
+
"@better-auth/api-key": ">=1.6.9",
|
|
60
|
+
"@better-auth/passkey": ">=1.6.10",
|
|
59
61
|
"@react-email/components": ">=1.0.12",
|
|
60
62
|
"@tanstack/react-query": ">=5.100.9",
|
|
61
|
-
"better-auth": ">=1.6.
|
|
63
|
+
"better-auth": ">=1.6.10",
|
|
62
64
|
"clsx": ">=2.0.0",
|
|
63
65
|
"react": ">=19.2.6",
|
|
64
66
|
"react-dom": ">=19.2.6",
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,8 @@ export * from "./hooks/use-auth-query"
|
|
|
12
12
|
export type * from "./lib/auth-client"
|
|
13
13
|
export * from "./lib/auth-plugin"
|
|
14
14
|
export * from "./lib/provider-icons"
|
|
15
|
+
export * from "./mutations/api-key/create-api-key-mutation"
|
|
16
|
+
export * from "./mutations/api-key/delete-api-key-mutation"
|
|
15
17
|
export * from "./mutations/auth/request-password-reset-mutation"
|
|
16
18
|
export * from "./mutations/auth/reset-password-mutation"
|
|
17
19
|
export * from "./mutations/auth/send-verification-email-mutation"
|
|
@@ -35,6 +37,7 @@ export * from "./mutations/settings/unlink-account-mutation"
|
|
|
35
37
|
export * from "./mutations/settings/update-user-mutation"
|
|
36
38
|
export * from "./mutations/username/is-username-available-mutation"
|
|
37
39
|
export * from "./mutations/username/sign-in-username-mutation"
|
|
40
|
+
export * from "./queries/api-key/list-api-keys-query"
|
|
38
41
|
export * from "./queries/auth/session-query"
|
|
39
42
|
export * from "./queries/auth-query-options"
|
|
40
43
|
export * from "./queries/multi-session/list-device-sessions-query"
|
package/src/lib/auth-client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { apiKeyClient } from "@better-auth/api-key/client"
|
|
1
2
|
import type { passkeyClient } from "@better-auth/passkey/client"
|
|
2
3
|
import type {
|
|
3
4
|
magicLinkClient,
|
|
@@ -26,6 +27,10 @@ export type PasskeyAuthClient = ReturnType<
|
|
|
26
27
|
typeof createAuthClient<{ plugins: [ReturnType<typeof passkeyClient>] }>
|
|
27
28
|
>
|
|
28
29
|
|
|
30
|
+
export type ApiKeyAuthClient = ReturnType<
|
|
31
|
+
typeof createAuthClient<{ plugins: [ReturnType<typeof apiKeyClient>] }>
|
|
32
|
+
>
|
|
33
|
+
|
|
29
34
|
export type UsernameAuthClient = ReturnType<
|
|
30
35
|
typeof createAuthClient<{ plugins: [ReturnType<typeof usernameClient>] }>
|
|
31
36
|
>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { apiKeyMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { ApiKeyAuthClient } from "../../lib/auth-client"
|
|
6
|
+
import { useListApiKeys } from "../../queries/api-key/list-api-keys-query"
|
|
7
|
+
|
|
8
|
+
export type CreateApiKeyParams<TAuthClient extends ApiKeyAuthClient> =
|
|
9
|
+
Parameters<TAuthClient["apiKey"]["create"]>[0]
|
|
10
|
+
|
|
11
|
+
export type CreateApiKeyOptions<TAuthClient extends ApiKeyAuthClient> = Omit<
|
|
12
|
+
ReturnType<typeof createApiKeyOptions<TAuthClient>>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Mutation options factory for creating an API key.
|
|
18
|
+
*
|
|
19
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
20
|
+
*/
|
|
21
|
+
export function createApiKeyOptions<TAuthClient extends ApiKeyAuthClient>(
|
|
22
|
+
authClient: TAuthClient
|
|
23
|
+
) {
|
|
24
|
+
const mutationKey = apiKeyMutationKeys.createApiKey
|
|
25
|
+
|
|
26
|
+
const mutationFn = (params: CreateApiKeyParams<TAuthClient>) =>
|
|
27
|
+
authClient.apiKey.create({
|
|
28
|
+
...params,
|
|
29
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return mutationOptions<
|
|
33
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
34
|
+
BetterFetchError,
|
|
35
|
+
Parameters<typeof mutationFn>[0]
|
|
36
|
+
>({
|
|
37
|
+
mutationKey,
|
|
38
|
+
mutationFn
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a mutation for creating an API key.
|
|
44
|
+
*
|
|
45
|
+
* Refetches the user's API key list on success unless disabled via options.
|
|
46
|
+
*
|
|
47
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
48
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
49
|
+
*/
|
|
50
|
+
export function useCreateApiKey<TAuthClient extends ApiKeyAuthClient>(
|
|
51
|
+
authClient: TAuthClient,
|
|
52
|
+
options?: CreateApiKeyOptions<TAuthClient>
|
|
53
|
+
) {
|
|
54
|
+
const { refetch } = useListApiKeys(authClient, { refetchOnMount: false })
|
|
55
|
+
|
|
56
|
+
return useMutation({
|
|
57
|
+
...createApiKeyOptions(authClient),
|
|
58
|
+
...options,
|
|
59
|
+
onSuccess: async (...args) => {
|
|
60
|
+
await refetch()
|
|
61
|
+
await options?.onSuccess?.(...args)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { apiKeyMutationKeys } from "@better-auth-ui/core/plugins"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { ApiKeyAuthClient } from "../../lib/auth-client"
|
|
6
|
+
import { useListApiKeys } from "../../queries/api-key/list-api-keys-query"
|
|
7
|
+
|
|
8
|
+
export type DeleteApiKeyParams<TAuthClient extends ApiKeyAuthClient> =
|
|
9
|
+
Parameters<TAuthClient["apiKey"]["delete"]>[0]
|
|
10
|
+
|
|
11
|
+
export type DeleteApiKeyOptions<TAuthClient extends ApiKeyAuthClient> = Omit<
|
|
12
|
+
ReturnType<typeof deleteApiKeyOptions<TAuthClient>>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Mutation options factory for deleting an API key.
|
|
18
|
+
*
|
|
19
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
20
|
+
*/
|
|
21
|
+
export function deleteApiKeyOptions<TAuthClient extends ApiKeyAuthClient>(
|
|
22
|
+
authClient: TAuthClient
|
|
23
|
+
) {
|
|
24
|
+
const mutationKey = apiKeyMutationKeys.deleteApiKey
|
|
25
|
+
|
|
26
|
+
const mutationFn = (params: DeleteApiKeyParams<TAuthClient>) =>
|
|
27
|
+
authClient.apiKey.delete({
|
|
28
|
+
...params,
|
|
29
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return mutationOptions<
|
|
33
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
34
|
+
BetterFetchError,
|
|
35
|
+
Parameters<typeof mutationFn>[0]
|
|
36
|
+
>({
|
|
37
|
+
mutationKey,
|
|
38
|
+
mutationFn
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a mutation for deleting an API key.
|
|
44
|
+
*
|
|
45
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
46
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
47
|
+
*/
|
|
48
|
+
export function useDeleteApiKey<TAuthClient extends ApiKeyAuthClient>(
|
|
49
|
+
authClient: TAuthClient,
|
|
50
|
+
options?: DeleteApiKeyOptions<TAuthClient>
|
|
51
|
+
) {
|
|
52
|
+
const { refetch } = useListApiKeys(authClient, { refetchOnMount: false })
|
|
53
|
+
|
|
54
|
+
return useMutation({
|
|
55
|
+
...deleteApiKeyOptions(authClient),
|
|
56
|
+
...options,
|
|
57
|
+
onSuccess: async (...args) => {
|
|
58
|
+
await refetch()
|
|
59
|
+
await options?.onSuccess?.(...args)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import {
|
|
3
|
+
type DataTag,
|
|
4
|
+
type QueryClient,
|
|
5
|
+
queryOptions,
|
|
6
|
+
skipToken,
|
|
7
|
+
useQuery
|
|
8
|
+
} from "@tanstack/react-query"
|
|
9
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
10
|
+
|
|
11
|
+
import type { ApiKeyAuthClient, InferData } from "../../lib/auth-client"
|
|
12
|
+
import { useSession } from "../auth/session-query"
|
|
13
|
+
|
|
14
|
+
export type ListApiKeysData<TAuthClient extends ApiKeyAuthClient> = InferData<
|
|
15
|
+
TAuthClient["apiKey"]["list"]
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export type ListApiKeysParams<TAuthClient extends ApiKeyAuthClient> =
|
|
19
|
+
Parameters<TAuthClient["apiKey"]["list"]>[0]
|
|
20
|
+
|
|
21
|
+
export type ListedApiKey<
|
|
22
|
+
TAuthClient extends ApiKeyAuthClient = ApiKeyAuthClient
|
|
23
|
+
> = NonNullable<ListApiKeysData<TAuthClient>>["apiKeys"][number]
|
|
24
|
+
|
|
25
|
+
export type ListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> = Omit<
|
|
26
|
+
ReturnType<typeof listApiKeysOptions<TAuthClient>>,
|
|
27
|
+
"queryKey" | "queryFn"
|
|
28
|
+
>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Query options factory for the current user's API keys.
|
|
32
|
+
*
|
|
33
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
34
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
35
|
+
* @param params - Parameters forwarded to `authClient.apiKey.list`.
|
|
36
|
+
*/
|
|
37
|
+
export function listApiKeysOptions<TAuthClient extends ApiKeyAuthClient>(
|
|
38
|
+
authClient: TAuthClient,
|
|
39
|
+
userId: string | undefined,
|
|
40
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
41
|
+
) {
|
|
42
|
+
type TData = ListApiKeysData<TAuthClient>
|
|
43
|
+
const queryKey = authQueryKeys.listApiKeys(userId, params?.query)
|
|
44
|
+
|
|
45
|
+
const options = queryOptions<TData, BetterFetchError, TData, typeof queryKey>(
|
|
46
|
+
{
|
|
47
|
+
queryKey,
|
|
48
|
+
queryFn: ({ signal }) =>
|
|
49
|
+
authClient.apiKey.list({
|
|
50
|
+
...params,
|
|
51
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
52
|
+
}) as Promise<TData>
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return options as typeof options & {
|
|
57
|
+
queryKey: DataTag<typeof queryKey, TData, BetterFetchError>
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const ensureListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
62
|
+
queryClient: QueryClient,
|
|
63
|
+
authClient: TAuthClient,
|
|
64
|
+
userId: string,
|
|
65
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
66
|
+
) => queryClient.ensureQueryData(listApiKeysOptions(authClient, userId, params))
|
|
67
|
+
|
|
68
|
+
export const prefetchListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
69
|
+
queryClient: QueryClient,
|
|
70
|
+
authClient: TAuthClient,
|
|
71
|
+
userId: string,
|
|
72
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
73
|
+
) => queryClient.prefetchQuery(listApiKeysOptions(authClient, userId, params))
|
|
74
|
+
|
|
75
|
+
export const fetchListApiKeys = <TAuthClient extends ApiKeyAuthClient>(
|
|
76
|
+
queryClient: QueryClient,
|
|
77
|
+
authClient: TAuthClient,
|
|
78
|
+
userId: string,
|
|
79
|
+
params?: ListApiKeysParams<TAuthClient>
|
|
80
|
+
) => queryClient.fetchQuery(listApiKeysOptions(authClient, userId, params))
|
|
81
|
+
|
|
82
|
+
export type UseListApiKeysOptions<TAuthClient extends ApiKeyAuthClient> =
|
|
83
|
+
ListApiKeysOptions<TAuthClient> & ListApiKeysParams<TAuthClient>
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Subscribe to the current user's API keys via TanStack Query.
|
|
87
|
+
*
|
|
88
|
+
* @param authClient - The Better Auth client with the API key plugin.
|
|
89
|
+
* @param options - `apiKey.list` params merged with `useQuery` options.
|
|
90
|
+
* @param queryClient - Optional custom `QueryClient`.
|
|
91
|
+
*/
|
|
92
|
+
export function useListApiKeys<TAuthClient extends ApiKeyAuthClient>(
|
|
93
|
+
authClient: TAuthClient,
|
|
94
|
+
options: UseListApiKeysOptions<TAuthClient> = {},
|
|
95
|
+
queryClient?: QueryClient
|
|
96
|
+
) {
|
|
97
|
+
const { data: session } = useSession(authClient, undefined, queryClient)
|
|
98
|
+
const userId = session?.user.id
|
|
99
|
+
|
|
100
|
+
const { query, fetchOptions, ...queryOptionsRest } = options
|
|
101
|
+
|
|
102
|
+
const baseOptions = listApiKeysOptions(authClient, userId, {
|
|
103
|
+
query,
|
|
104
|
+
fetchOptions
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return useQuery(
|
|
108
|
+
{
|
|
109
|
+
...queryOptionsRest,
|
|
110
|
+
...baseOptions,
|
|
111
|
+
queryFn: userId ? baseOptions.queryFn : skipToken
|
|
112
|
+
},
|
|
113
|
+
queryClient
|
|
114
|
+
)
|
|
115
|
+
}
|