@better-auth-ui/react 1.6.2 → 1.6.4
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/components/auth/auth-provider.d.ts +23 -8
- package/dist/components/auth/auth-provider.js +32 -17
- package/dist/components/{email → auth/email}/email-changed.js +2 -2
- package/dist/components/{email → auth/email}/email-localization.js +1 -1
- package/dist/components/{email → auth/email}/email-styles.js +1 -1
- package/dist/components/{email → auth/email}/email-verification.js +2 -2
- package/dist/components/{email → auth/email}/magic-link.js +2 -2
- package/dist/components/{email → auth/email}/new-device.js +2 -2
- package/dist/components/{email → auth/email}/otp-email.js +2 -2
- package/dist/components/{email → auth/email}/password-changed.js +2 -2
- package/dist/components/{email → auth/email}/reset-password.js +2 -2
- package/dist/email.d.ts +1 -0
- package/dist/email.js +11 -0
- package/dist/hooks/auth/use-authenticate.d.ts +6 -5
- package/dist/hooks/auth/use-authenticate.js +12 -12
- package/dist/hooks/auth/use-user.d.ts +18 -311
- package/dist/hooks/auth/use-user.js +5 -5
- package/dist/hooks/use-auth-mutation.d.ts +17 -0
- package/dist/hooks/use-auth-mutation.js +11 -0
- package/dist/hooks/use-auth-plugin.d.ts +31 -0
- package/dist/hooks/use-auth-plugin.js +10 -0
- package/dist/hooks/use-auth-query.d.ts +14 -0
- package/dist/hooks/use-auth-query.js +15 -0
- package/dist/index.d.ts +35 -34
- package/dist/index.js +74 -83
- package/dist/lib/auth-client.d.ts +23 -3687
- package/dist/lib/auth-plugin.d.ts +59 -0
- package/dist/lib/auth-server.d.ts +16 -0
- package/dist/mutations/auth/request-password-reset-mutation.d.ts +26 -0
- package/dist/mutations/auth/request-password-reset-mutation.js +24 -0
- package/dist/mutations/auth/reset-password-mutation.d.ts +25 -0
- package/dist/mutations/auth/reset-password-mutation.js +24 -0
- package/dist/mutations/auth/send-verification-email-mutation.d.ts +24 -0
- package/dist/mutations/auth/send-verification-email-mutation.js +24 -0
- package/dist/mutations/auth/sign-in-email-mutation.d.ts +71 -0
- package/dist/mutations/auth/sign-in-email-mutation.js +29 -0
- package/dist/mutations/auth/sign-in-social-mutation.d.ts +77 -0
- package/dist/mutations/auth/sign-in-social-mutation.js +24 -0
- package/dist/mutations/auth/sign-out-mutation.d.ts +25 -0
- package/dist/mutations/auth/sign-out-mutation.js +28 -0
- package/dist/mutations/auth/sign-up-email-mutation.d.ts +105 -0
- package/dist/mutations/auth/sign-up-email-mutation.js +29 -0
- package/dist/mutations/auth-mutation-options.d.ts +42 -0
- package/dist/mutations/auth-mutation-options.js +19 -0
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +24 -0
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +24 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +25 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.js +29 -0
- package/dist/mutations/multi-session/set-active-session-mutation.d.ts +62 -0
- package/dist/mutations/multi-session/set-active-session-mutation.js +31 -0
- package/dist/mutations/passkey/add-passkey-mutation.d.ts +71 -0
- package/dist/mutations/passkey/add-passkey-mutation.js +29 -0
- package/dist/mutations/passkey/delete-passkey-mutation.d.ts +25 -0
- package/dist/mutations/passkey/delete-passkey-mutation.js +29 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +105 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.js +29 -0
- package/dist/mutations/settings/change-email-mutation.d.ts +25 -0
- package/dist/mutations/settings/change-email-mutation.js +29 -0
- package/dist/mutations/settings/change-password-mutation.d.ts +78 -0
- package/dist/mutations/settings/change-password-mutation.js +24 -0
- package/dist/mutations/settings/delete-user-mutation.d.ts +26 -0
- package/dist/mutations/settings/delete-user-mutation.js +24 -0
- package/dist/mutations/settings/link-social-mutation.d.ts +26 -0
- package/dist/mutations/settings/link-social-mutation.js +24 -0
- package/dist/mutations/settings/revoke-session-mutation.d.ts +25 -0
- package/dist/mutations/settings/revoke-session-mutation.js +29 -0
- package/dist/mutations/settings/unlink-account-mutation.d.ts +25 -0
- package/dist/mutations/settings/unlink-account-mutation.js +29 -0
- package/dist/mutations/settings/update-user-mutation.d.ts +25 -0
- package/dist/mutations/settings/update-user-mutation.js +35 -0
- package/dist/mutations/username/is-username-available-mutation.d.ts +27 -0
- package/dist/mutations/username/is-username-available-mutation.js +24 -0
- package/dist/mutations/username/sign-in-username-mutation.d.ts +75 -0
- package/dist/mutations/username/sign-in-username-mutation.js +29 -0
- package/dist/queries/auth/session-query.d.ts +71 -0
- package/dist/queries/auth/session-query.js +30 -0
- package/dist/queries/auth-query-options.d.ts +40 -0
- package/dist/queries/auth-query-options.js +17 -0
- package/dist/queries/multi-session/list-device-sessions-query.d.ts +76 -0
- package/dist/queries/multi-session/list-device-sessions-query.js +31 -0
- package/dist/queries/passkey/list-passkeys-query.d.ts +74 -0
- package/dist/queries/passkey/list-passkeys-query.js +31 -0
- package/dist/queries/settings/account-info-query.d.ts +85 -0
- package/dist/queries/settings/account-info-query.js +31 -0
- package/dist/queries/settings/list-accounts-query.d.ts +76 -0
- package/dist/queries/settings/list-accounts-query.js +31 -0
- package/dist/queries/settings/list-sessions-query.d.ts +74 -0
- package/dist/queries/settings/list-sessions-query.js +31 -0
- package/dist/server/queries/auth/session-query.d.ts +57 -0
- package/dist/server/queries/auth/session-query.js +13 -0
- package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +60 -0
- package/dist/server/queries/multi-session/list-device-sessions-query.js +12 -0
- package/dist/server/queries/passkey/list-passkeys-query.d.ts +60 -0
- package/dist/server/queries/passkey/list-passkeys-query.js +12 -0
- package/dist/server/queries/settings/account-info-query.d.ts +68 -0
- package/dist/server/queries/settings/account-info-query.js +12 -0
- package/dist/server/queries/settings/list-accounts-query.d.ts +60 -0
- package/dist/server/queries/settings/list-accounts-query.js +12 -0
- package/dist/server/queries/settings/list-sessions-query.d.ts +60 -0
- package/dist/server/queries/settings/list-sessions-query.js +12 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +7 -0
- package/package.json +24 -22
- package/src/components/auth/auth-provider.tsx +87 -24
- package/src/components/{email → auth/email}/email-changed.tsx +1 -1
- package/src/components/{email → auth/email}/email-verification.tsx +1 -1
- package/src/components/{email → auth/email}/magic-link.tsx +1 -1
- package/src/components/{email → auth/email}/new-device.tsx +1 -1
- package/src/components/{email → auth/email}/otp-email.tsx +1 -1
- package/src/components/{email → auth/email}/password-changed.tsx +1 -1
- package/src/components/{email → auth/email}/reset-password.tsx +1 -1
- package/src/email.ts +1 -0
- package/src/hooks/auth/use-authenticate.ts +13 -10
- package/src/hooks/auth/use-user.ts +12 -8
- package/src/hooks/use-auth-mutation.ts +47 -0
- package/src/hooks/use-auth-plugin.ts +50 -0
- package/src/hooks/use-auth-query.ts +40 -0
- package/src/index.ts +35 -34
- package/src/lib/auth-client.ts +33 -31
- package/src/lib/auth-plugin.ts +75 -0
- package/src/lib/auth-server.ts +30 -0
- package/src/mutations/auth/request-password-reset-mutation.ts +58 -0
- package/src/mutations/auth/reset-password-mutation.ts +60 -0
- package/src/mutations/auth/send-verification-email-mutation.ts +58 -0
- package/src/mutations/auth/sign-in-email-mutation.ts +78 -0
- package/src/mutations/auth/sign-in-social-mutation.ts +64 -0
- package/src/mutations/auth/sign-out-mutation.ts +71 -0
- package/src/mutations/auth/sign-up-email-mutation.ts +74 -0
- package/src/mutations/auth-mutation-options.ts +94 -0
- package/src/mutations/magic-link/sign-in-magic-link-mutation.ts +59 -0
- package/src/mutations/multi-session/revoke-multi-session-mutation.ts +70 -0
- package/src/mutations/multi-session/set-active-session-mutation.ts +98 -0
- package/src/mutations/passkey/add-passkey-mutation.ts +66 -0
- package/src/mutations/passkey/delete-passkey-mutation.ts +66 -0
- package/src/mutations/passkey/sign-in-passkey-mutation.ts +74 -0
- package/src/mutations/settings/change-email-mutation.ts +67 -0
- package/src/mutations/settings/change-password-mutation.ts +59 -0
- package/src/mutations/settings/delete-user-mutation.ts +59 -0
- package/src/mutations/settings/link-social-mutation.ts +59 -0
- package/src/mutations/settings/revoke-session-mutation.ts +69 -0
- package/src/mutations/settings/unlink-account-mutation.ts +67 -0
- package/src/mutations/settings/update-user-mutation.ts +82 -0
- package/src/mutations/username/is-username-available-mutation.ts +62 -0
- package/src/mutations/username/sign-in-username-mutation.ts +74 -0
- package/src/queries/auth/session-query.ts +135 -0
- package/src/queries/auth-query-options.ts +83 -0
- package/src/queries/multi-session/list-device-sessions-query.ts +177 -0
- package/src/queries/passkey/list-passkeys-query.ts +154 -0
- package/src/queries/settings/account-info-query.ts +158 -0
- package/src/queries/settings/list-accounts-query.ts +156 -0
- package/src/queries/settings/list-sessions-query.ts +154 -0
- package/src/server/queries/auth/session-query.ts +94 -0
- package/src/server/queries/multi-session/list-device-sessions-query.ts +102 -0
- package/src/server/queries/passkey/list-passkeys-query.ts +100 -0
- package/src/server/queries/settings/account-info-query.ts +101 -0
- package/src/server/queries/settings/list-accounts-query.ts +101 -0
- package/src/server/queries/settings/list-sessions-query.ts +101 -0
- package/src/server.ts +7 -0
- package/dist/core.d.ts +0 -1
- package/dist/core.js +0 -1
- package/dist/hooks/auth/use-auth-mutation.d.ts +0 -18
- package/dist/hooks/auth/use-auth-mutation.js +0 -13
- package/dist/hooks/auth/use-auth-query.d.ts +0 -24
- package/dist/hooks/auth/use-auth-query.js +0 -13
- package/dist/hooks/auth/use-is-username-available.d.ts +0 -19
- package/dist/hooks/auth/use-is-username-available.js +0 -12
- package/dist/hooks/auth/use-request-password-reset.d.ts +0 -25
- package/dist/hooks/auth/use-request-password-reset.js +0 -12
- package/dist/hooks/auth/use-reset-password.d.ts +0 -39
- package/dist/hooks/auth/use-reset-password.js +0 -12
- package/dist/hooks/auth/use-send-verification-email.d.ts +0 -23
- package/dist/hooks/auth/use-send-verification-email.js +0 -12
- package/dist/hooks/auth/use-session.d.ts +0 -9
- package/dist/hooks/auth/use-session.js +0 -15
- package/dist/hooks/auth/use-sign-in-email.d.ts +0 -52
- package/dist/hooks/auth/use-sign-in-email.js +0 -18
- package/dist/hooks/auth/use-sign-in-magic-link.d.ts +0 -31
- package/dist/hooks/auth/use-sign-in-magic-link.js +0 -12
- package/dist/hooks/auth/use-sign-in-passkey.d.ts +0 -58
- package/dist/hooks/auth/use-sign-in-passkey.js +0 -18
- package/dist/hooks/auth/use-sign-in-social.d.ts +0 -92
- package/dist/hooks/auth/use-sign-in-social.js +0 -12
- package/dist/hooks/auth/use-sign-in-username.d.ts +0 -53
- package/dist/hooks/auth/use-sign-in-username.js +0 -18
- package/dist/hooks/auth/use-sign-out.d.ts +0 -18
- package/dist/hooks/auth/use-sign-out.js +0 -18
- package/dist/hooks/auth/use-sign-up-email.d.ts +0 -1269
- package/dist/hooks/auth/use-sign-up-email.js +0 -18
- package/dist/hooks/settings/use-account-info.d.ts +0 -17
- package/dist/hooks/settings/use-account-info.js +0 -21
- package/dist/hooks/settings/use-add-passkey.d.ts +0 -43
- package/dist/hooks/settings/use-add-passkey.js +0 -18
- package/dist/hooks/settings/use-change-email.d.ts +0 -24
- package/dist/hooks/settings/use-change-email.js +0 -18
- package/dist/hooks/settings/use-change-password.d.ts +0 -53
- package/dist/hooks/settings/use-change-password.js +0 -12
- package/dist/hooks/settings/use-delete-passkey.d.ts +0 -21
- package/dist/hooks/settings/use-delete-passkey.js +0 -18
- package/dist/hooks/settings/use-delete-user.d.ts +0 -41
- package/dist/hooks/settings/use-delete-user.js +0 -12
- package/dist/hooks/settings/use-link-social.d.ts +0 -46
- package/dist/hooks/settings/use-link-social.js +0 -12
- package/dist/hooks/settings/use-list-accounts.d.ts +0 -20
- package/dist/hooks/settings/use-list-accounts.js +0 -21
- package/dist/hooks/settings/use-list-device-sessions.d.ts +0 -11
- package/dist/hooks/settings/use-list-device-sessions.js +0 -21
- package/dist/hooks/settings/use-list-sessions.d.ts +0 -20
- package/dist/hooks/settings/use-list-sessions.js +0 -21
- package/dist/hooks/settings/use-list-user-passkeys.d.ts +0 -11
- package/dist/hooks/settings/use-list-user-passkeys.js +0 -21
- package/dist/hooks/settings/use-revoke-multi-session.d.ts +0 -19
- package/dist/hooks/settings/use-revoke-multi-session.js +0 -18
- package/dist/hooks/settings/use-revoke-session.d.ts +0 -19
- package/dist/hooks/settings/use-revoke-session.js +0 -18
- package/dist/hooks/settings/use-set-active-session.d.ts +0 -37
- package/dist/hooks/settings/use-set-active-session.js +0 -21
- package/dist/hooks/settings/use-unlink-account.d.ts +0 -21
- package/dist/hooks/settings/use-unlink-account.js +0 -18
- package/dist/hooks/settings/use-update-user.d.ts +0 -11
- package/dist/hooks/settings/use-update-user.js +0 -25
- package/dist/lib/auth-client.js +0 -11
- package/dist/lib/auth-config.d.ts +0 -43
- package/dist/lib/auth-context.d.ts +0 -2
- package/dist/lib/auth-context.js +0 -6
- package/src/core.ts +0 -1
- package/src/hooks/auth/use-auth-mutation.ts +0 -56
- package/src/hooks/auth/use-auth-query.ts +0 -50
- package/src/hooks/auth/use-is-username-available.ts +0 -22
- package/src/hooks/auth/use-request-password-reset.ts +0 -22
- package/src/hooks/auth/use-reset-password.ts +0 -21
- package/src/hooks/auth/use-send-verification-email.ts +0 -21
- package/src/hooks/auth/use-session.ts +0 -27
- package/src/hooks/auth/use-sign-in-email.ts +0 -34
- package/src/hooks/auth/use-sign-in-magic-link.ts +0 -21
- package/src/hooks/auth/use-sign-in-passkey.ts +0 -34
- package/src/hooks/auth/use-sign-in-social.ts +0 -21
- package/src/hooks/auth/use-sign-in-username.ts +0 -34
- package/src/hooks/auth/use-sign-out.ts +0 -33
- package/src/hooks/auth/use-sign-up-email.ts +0 -34
- package/src/hooks/settings/use-account-info.ts +0 -31
- package/src/hooks/settings/use-add-passkey.ts +0 -32
- package/src/hooks/settings/use-change-email.ts +0 -33
- package/src/hooks/settings/use-change-password.ts +0 -19
- package/src/hooks/settings/use-delete-passkey.ts +0 -32
- package/src/hooks/settings/use-delete-user.ts +0 -19
- package/src/hooks/settings/use-link-social.ts +0 -19
- package/src/hooks/settings/use-list-accounts.ts +0 -29
- package/src/hooks/settings/use-list-device-sessions.ts +0 -34
- package/src/hooks/settings/use-list-sessions.ts +0 -28
- package/src/hooks/settings/use-list-user-passkeys.ts +0 -30
- package/src/hooks/settings/use-revoke-multi-session.ts +0 -30
- package/src/hooks/settings/use-revoke-session.ts +0 -30
- package/src/hooks/settings/use-set-active-session.ts +0 -47
- package/src/hooks/settings/use-unlink-account.ts +0 -30
- package/src/hooks/settings/use-update-user.ts +0 -43
- package/src/lib/auth-config.ts +0 -48
- package/src/lib/auth-context.ts +0 -6
- /package/dist/components/{email → auth/email}/email-changed.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-localization.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-styles.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-verification.d.ts +0 -0
- /package/dist/components/{email → auth/email}/index.d.ts +0 -0
- /package/dist/components/{email → auth/email}/index.js +0 -0
- /package/dist/components/{email → auth/email}/magic-link.d.ts +0 -0
- /package/dist/components/{email → auth/email}/new-device.d.ts +0 -0
- /package/dist/components/{email → auth/email}/otp-email.d.ts +0 -0
- /package/dist/components/{email → auth/email}/password-changed.d.ts +0 -0
- /package/dist/components/{email → auth/email}/reset-password.d.ts +0 -0
- /package/src/components/{email → auth/email}/email-localization.tsx +0 -0
- /package/src/components/{email → auth/email}/email-styles.tsx +0 -0
- /package/src/components/{email → auth/email}/index.ts +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { InferData, MultiSessionAuthClient } from '../../lib/auth-client';
|
|
4
|
+
export type ListDeviceSessionsData<TAuthClient extends MultiSessionAuthClient = MultiSessionAuthClient> = InferData<TAuthClient["multiSession"]["listDeviceSessions"]>;
|
|
5
|
+
export type ListDeviceSession<TAuthClient extends MultiSessionAuthClient = MultiSessionAuthClient> = NonNullable<ListDeviceSessionsData<TAuthClient>>[number];
|
|
6
|
+
export type ListDeviceSessionsParams<TAuthClient extends MultiSessionAuthClient> = Parameters<TAuthClient["multiSession"]["listDeviceSessions"]>[0];
|
|
7
|
+
export type ListDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient> = Omit<ReturnType<typeof listDeviceSessionsOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for the current user's device sessions.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListDeviceSessionsParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, BetterFetchError, InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, readonly ["auth", "user", string | undefined, "listDeviceSessions", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, readonly ["auth", "user", string | undefined, "listDeviceSessions", Record<string, any> | null], never> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
queryKey: readonly ["auth", "user", string | undefined, "listDeviceSessions", Record<string, any> | null] & {
|
|
19
|
+
[dataTagSymbol]: InferData<TAuthClient["multiSession"]["listDeviceSessions"]>;
|
|
20
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
21
|
+
};
|
|
22
|
+
}) & {
|
|
23
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "listDeviceSessions", Record<string, any> | null], InferData<TAuthClient["multiSession"]["listDeviceSessions"]>, BetterFetchError>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get the current user's device sessions from the query cache, calling
|
|
27
|
+
* `fetchListDeviceSessions` under the hood if no cached entry exists.
|
|
28
|
+
* Resolves with the device session list, making it ideal for loaders or
|
|
29
|
+
* `beforeLoad` guards.
|
|
30
|
+
*
|
|
31
|
+
* @param queryClient - The React Query client.
|
|
32
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
33
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
34
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ensureListDeviceSessions: <TAuthClient extends MultiSessionAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListDeviceSessionsParams<TAuthClient>) => Promise<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>>;
|
|
37
|
+
/**
|
|
38
|
+
* Prefetch the current user's device sessions into the query cache. Behaves
|
|
39
|
+
* like `fetchListDeviceSessions`, but does not throw on error and does not
|
|
40
|
+
* return the data — use this to warm the cache without blocking navigation.
|
|
41
|
+
*
|
|
42
|
+
* @param queryClient - The React Query client.
|
|
43
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
44
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
45
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
46
|
+
*/
|
|
47
|
+
export declare const prefetchListDeviceSessions: <TAuthClient extends MultiSessionAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListDeviceSessionsParams<TAuthClient>) => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Fetch and cache the current user's device sessions, resolving with the
|
|
50
|
+
* data or throwing on error. If a cached entry exists and is neither
|
|
51
|
+
* invalidated nor older than `staleTime`, the cached value is returned
|
|
52
|
+
* without a network call; otherwise the latest data is fetched.
|
|
53
|
+
*
|
|
54
|
+
* @param queryClient - The React Query client.
|
|
55
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
56
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
57
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
58
|
+
*/
|
|
59
|
+
export declare const fetchListDeviceSessions: <TAuthClient extends MultiSessionAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListDeviceSessionsParams<TAuthClient>) => Promise<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>>;
|
|
60
|
+
export type UseListDeviceSessionsOptions<TAuthClient extends MultiSessionAuthClient> = ListDeviceSessionsOptions<TAuthClient> & ListDeviceSessionsParams<TAuthClient>;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe to the current user's device sessions (multi-session account
|
|
63
|
+
* switcher) via TanStack Query.
|
|
64
|
+
*
|
|
65
|
+
* Shares a query key with the server-side `listDeviceSessionsOptions`, so
|
|
66
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
67
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
68
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
69
|
+
*
|
|
70
|
+
* @param authClient - The Better Auth client with the multi-session plugin.
|
|
71
|
+
* @param options - `listDeviceSessions` params (`query`, `fetchOptions`)
|
|
72
|
+
* merged with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
73
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
74
|
+
* from the nearest `QueryClientProvider`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useListDeviceSessions<TAuthClient extends MultiSessionAuthClient>(authClient: TAuthClient, options?: UseListDeviceSessionsOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["multiSession"]["listDeviceSessions"]>>, 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/multi-session/list-device-sessions-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.listDeviceSessions(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.multiSession.listDeviceSessions({
|
|
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 ensureListDeviceSessions, c as fetchListDeviceSessions, a as listDeviceSessionsOptions, s as prefetchListDeviceSessions, l as useListDeviceSessions };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { InferData, PasskeyAuthClient } from '../../lib/auth-client';
|
|
4
|
+
export type ListPasskeysData<TAuthClient extends PasskeyAuthClient> = InferData<TAuthClient["passkey"]["listUserPasskeys"]>;
|
|
5
|
+
export type ListPasskeysParams<TAuthClient extends PasskeyAuthClient> = Parameters<TAuthClient["passkey"]["listUserPasskeys"]>[0];
|
|
6
|
+
export type ListPasskey<TAuthClient extends PasskeyAuthClient = PasskeyAuthClient> = NonNullable<ListPasskeysData<TAuthClient>>[number];
|
|
7
|
+
export type ListPasskeysOptions<TAuthClient extends PasskeyAuthClient> = Omit<ReturnType<typeof listPasskeysOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for the current user's passkeys.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listPasskeysOptions<TAuthClient extends PasskeyAuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListPasskeysParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["passkey"]["listUserPasskeys"]>, BetterFetchError, InferData<TAuthClient["passkey"]["listUserPasskeys"]>, readonly ["auth", "user", string | undefined, "listPasskeys", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["passkey"]["listUserPasskeys"]>, readonly ["auth", "user", string | undefined, "listPasskeys", Record<string, any> | null], never> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
queryKey: readonly ["auth", "user", string | undefined, "listPasskeys", Record<string, any> | null] & {
|
|
19
|
+
[dataTagSymbol]: InferData<TAuthClient["passkey"]["listUserPasskeys"]>;
|
|
20
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
21
|
+
};
|
|
22
|
+
}) & {
|
|
23
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "listPasskeys", Record<string, any> | null], InferData<TAuthClient["passkey"]["listUserPasskeys"]>, BetterFetchError>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get the current user's passkeys from the query cache, calling
|
|
27
|
+
* `fetchListPasskeys` under the hood if no cached entry exists. Resolves
|
|
28
|
+
* with the passkey list, making it ideal for loaders or `beforeLoad` guards.
|
|
29
|
+
*
|
|
30
|
+
* @param queryClient - The React Query client.
|
|
31
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
32
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
33
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ensureListPasskeys: <TAuthClient extends PasskeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListPasskeysParams<TAuthClient>) => Promise<InferData<TAuthClient["passkey"]["listUserPasskeys"]>>;
|
|
36
|
+
/**
|
|
37
|
+
* Prefetch the current user's passkeys into the query cache. Behaves like
|
|
38
|
+
* `fetchListPasskeys`, but does not throw on error and does not return
|
|
39
|
+
* the data — use this to warm the cache without blocking navigation.
|
|
40
|
+
*
|
|
41
|
+
* @param queryClient - The React Query client.
|
|
42
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
43
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
44
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const prefetchListPasskeys: <TAuthClient extends PasskeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListPasskeysParams<TAuthClient>) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch and cache the current user's passkeys, resolving with the data or
|
|
49
|
+
* throwing on error. If a cached entry exists and is neither invalidated
|
|
50
|
+
* nor older than `staleTime`, the cached value is returned without a
|
|
51
|
+
* network call; otherwise the latest data is fetched.
|
|
52
|
+
*
|
|
53
|
+
* @param queryClient - The React Query client.
|
|
54
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
55
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
56
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const fetchListPasskeys: <TAuthClient extends PasskeyAuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListPasskeysParams<TAuthClient>) => Promise<InferData<TAuthClient["passkey"]["listUserPasskeys"]>>;
|
|
59
|
+
export type UseListPasskeysOptions<TAuthClient extends PasskeyAuthClient> = ListPasskeysOptions<TAuthClient> & ListPasskeysParams<TAuthClient>;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to the current user's passkeys via TanStack Query.
|
|
62
|
+
*
|
|
63
|
+
* Shares a query key with the server-side `listPasskeysOptions`, so
|
|
64
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
65
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
66
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
67
|
+
*
|
|
68
|
+
* @param authClient - The Better Auth client with the passkey plugin.
|
|
69
|
+
* @param options - `listPasskeys` params (`query`, `fetchOptions`) merged
|
|
70
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
71
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
72
|
+
* from the nearest `QueryClientProvider`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useListPasskeys<TAuthClient extends PasskeyAuthClient>(authClient: TAuthClient, options?: UseListPasskeysOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["passkey"]["listUserPasskeys"]>>, 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/passkey/list-passkeys-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.listPasskeys(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.passkey.listUserPasskeys({
|
|
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 ensureListPasskeys, c as fetchListPasskeys, a as listPasskeysOptions, s as prefetchListPasskeys, l as useListPasskeys };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { AuthClient, InferData } from '../../lib/auth-client';
|
|
4
|
+
export type AccountInfoData<TAuthClient extends AuthClient> = InferData<TAuthClient["accountInfo"]>;
|
|
5
|
+
export type AccountInfoParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["accountInfo"]>[0];
|
|
6
|
+
export type AccountInfo<TAuthClient extends AuthClient = AuthClient> = NonNullable<AccountInfoData<TAuthClient>>;
|
|
7
|
+
export type AccountInfoOptions<TAuthClient extends AuthClient> = Omit<ReturnType<typeof accountInfoOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for provider-specific account info.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function accountInfoOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: AccountInfoParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["accountInfo"]>, BetterFetchError, InferData<TAuthClient["accountInfo"]>, readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
16
|
+
accountId?: string | undefined;
|
|
17
|
+
} | null]>, "queryFn"> & {
|
|
18
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["accountInfo"]>, readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
19
|
+
accountId?: string | undefined;
|
|
20
|
+
} | null], never> | undefined;
|
|
21
|
+
} & {
|
|
22
|
+
queryKey: readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
23
|
+
accountId?: string | undefined;
|
|
24
|
+
} | null] & {
|
|
25
|
+
[dataTagSymbol]: InferData<TAuthClient["accountInfo"]>;
|
|
26
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
27
|
+
};
|
|
28
|
+
}) & {
|
|
29
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "accountInfo", {
|
|
30
|
+
accountId?: string | undefined;
|
|
31
|
+
} | null], InferData<TAuthClient["accountInfo"]>, BetterFetchError>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Get the current user's provider-specific account info from the query
|
|
35
|
+
* cache, calling `fetchAccountInfo` under the hood if no cached entry
|
|
36
|
+
* exists. Resolves with the data, making it ideal for loaders or
|
|
37
|
+
* `beforeLoad` guards.
|
|
38
|
+
*
|
|
39
|
+
* @param queryClient - The React Query client.
|
|
40
|
+
* @param authClient - The Better Auth client.
|
|
41
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
42
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ensureAccountInfo: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: AccountInfoParams<TAuthClient>) => Promise<InferData<TAuthClient["accountInfo"]>>;
|
|
45
|
+
/**
|
|
46
|
+
* Prefetch the current user's provider-specific account info into the query
|
|
47
|
+
* cache. Behaves like `fetchAccountInfo`, but does not throw on error and
|
|
48
|
+
* does not return the data — use this to warm the cache without blocking
|
|
49
|
+
* navigation.
|
|
50
|
+
*
|
|
51
|
+
* @param queryClient - The React Query client.
|
|
52
|
+
* @param authClient - The Better Auth client.
|
|
53
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
54
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
55
|
+
*/
|
|
56
|
+
export declare const prefetchAccountInfo: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: AccountInfoParams<TAuthClient>) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Fetch and cache the current user's provider-specific account info,
|
|
59
|
+
* resolving with the data or throwing on error. If a cached entry exists
|
|
60
|
+
* and is neither invalidated nor older than `staleTime`, the cached value
|
|
61
|
+
* is returned without a network call; otherwise the latest data is fetched.
|
|
62
|
+
*
|
|
63
|
+
* @param queryClient - The React Query client.
|
|
64
|
+
* @param authClient - The Better Auth client.
|
|
65
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
66
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
67
|
+
*/
|
|
68
|
+
export declare const fetchAccountInfo: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: AccountInfoParams<TAuthClient>) => Promise<InferData<TAuthClient["accountInfo"]>>;
|
|
69
|
+
export type UseAccountInfoOptions<TAuthClient extends AuthClient> = AccountInfoOptions<TAuthClient> & AccountInfoParams<TAuthClient>;
|
|
70
|
+
/**
|
|
71
|
+
* Subscribe to provider-specific info for a linked account via TanStack Query.
|
|
72
|
+
*
|
|
73
|
+
* Shares a query key with the server-side `accountInfoOptions`, so
|
|
74
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
75
|
+
* The query is gated on both a signed-in user and a resolved `accountId`;
|
|
76
|
+
* until both are present, the underlying `queryFn` is replaced with
|
|
77
|
+
* `skipToken`.
|
|
78
|
+
*
|
|
79
|
+
* @param authClient - The Better Auth client.
|
|
80
|
+
* @param options - `accountInfo` params (`query`, `fetchOptions`) merged
|
|
81
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
82
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
83
|
+
* from the nearest `QueryClientProvider`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function useAccountInfo<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseAccountInfoOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["accountInfo"]>>, 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/settings/account-info-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.accountInfo(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.accountInfo({
|
|
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
|
+
}), p = !!(c && l?.accountId);
|
|
24
|
+
return i({
|
|
25
|
+
...d,
|
|
26
|
+
...f,
|
|
27
|
+
queryFn: p ? f.queryFn : r
|
|
28
|
+
}, o);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { a as accountInfoOptions, o as ensureAccountInfo, c as fetchAccountInfo, s as prefetchAccountInfo, l as useAccountInfo };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { AuthClient, InferData } from '../../lib/auth-client';
|
|
4
|
+
export type ListAccountsData<TAuthClient extends AuthClient> = InferData<TAuthClient["listAccounts"]>;
|
|
5
|
+
export type ListAccountsParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["listAccounts"]>[0];
|
|
6
|
+
export type ListAccount<TAuthClient extends AuthClient = AuthClient> = NonNullable<ListAccountsData<TAuthClient>>[number];
|
|
7
|
+
export type ListAccountsOptions<TAuthClient extends AuthClient> = Omit<ReturnType<typeof listAccountsOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for a user's linked social accounts.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listAccountsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListAccountsParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["listAccounts"]>, BetterFetchError, InferData<TAuthClient["listAccounts"]>, readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["listAccounts"]>, readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null], never> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
queryKey: readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null] & {
|
|
19
|
+
[dataTagSymbol]: InferData<TAuthClient["listAccounts"]>;
|
|
20
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
21
|
+
};
|
|
22
|
+
}) & {
|
|
23
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "listAccounts", Record<string, any> | null], InferData<TAuthClient["listAccounts"]>, BetterFetchError>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get the current user's linked social accounts from the query cache,
|
|
27
|
+
* calling `fetchListAccounts` under the hood if no cached entry exists.
|
|
28
|
+
* Resolves with the account list, making it ideal for loaders or
|
|
29
|
+
* `beforeLoad` guards.
|
|
30
|
+
*
|
|
31
|
+
* @param queryClient - The React Query client.
|
|
32
|
+
* @param authClient - The Better Auth client.
|
|
33
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
34
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ensureListAccounts: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListAccountsParams<TAuthClient>) => Promise<InferData<TAuthClient["listAccounts"]>>;
|
|
37
|
+
/**
|
|
38
|
+
* Prefetch the current user's linked social accounts into the query cache.
|
|
39
|
+
* Behaves like `fetchListAccounts`, but does not throw on error and does
|
|
40
|
+
* not return the data — use this to warm the cache without blocking
|
|
41
|
+
* navigation.
|
|
42
|
+
*
|
|
43
|
+
* @param queryClient - The React Query client.
|
|
44
|
+
* @param authClient - The Better Auth client.
|
|
45
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
46
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const prefetchListAccounts: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListAccountsParams<TAuthClient>) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Fetch and cache the current user's linked social accounts, resolving
|
|
51
|
+
* with the data or throwing on error. If a cached entry exists and is
|
|
52
|
+
* neither invalidated nor older than `staleTime`, the cached value is
|
|
53
|
+
* returned without a network call; otherwise the latest data is fetched.
|
|
54
|
+
*
|
|
55
|
+
* @param queryClient - The React Query client.
|
|
56
|
+
* @param authClient - The Better Auth client.
|
|
57
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
58
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
59
|
+
*/
|
|
60
|
+
export declare const fetchListAccounts: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListAccountsParams<TAuthClient>) => Promise<InferData<TAuthClient["listAccounts"]>>;
|
|
61
|
+
export type UseListAccountsOptions<TAuthClient extends AuthClient> = ListAccountsOptions<TAuthClient> & ListAccountsParams<TAuthClient>;
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to the current user's linked social accounts via TanStack Query.
|
|
64
|
+
*
|
|
65
|
+
* Shares a query key with the server-side `listAccountsOptions`, so
|
|
66
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
67
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
68
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
69
|
+
*
|
|
70
|
+
* @param authClient - The Better Auth client.
|
|
71
|
+
* @param options - `listAccounts` params (`query`, `fetchOptions`) merged
|
|
72
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
73
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
74
|
+
* from the nearest `QueryClientProvider`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useListAccounts<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListAccountsOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["listAccounts"]>>, 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/settings/list-accounts-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.listAccounts(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.listAccounts({
|
|
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 ensureListAccounts, c as fetchListAccounts, a as listAccountsOptions, s as prefetchListAccounts, l as useListAccounts };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { BetterFetchError } from 'better-auth/react';
|
|
3
|
+
import { AuthClient, InferData } from '../../lib/auth-client';
|
|
4
|
+
export type ListSessionsData<TAuthClient extends AuthClient> = InferData<TAuthClient["listSessions"]>;
|
|
5
|
+
export type ListSessionsParams<TAuthClient extends AuthClient> = Parameters<TAuthClient["listSessions"]>[0];
|
|
6
|
+
export type ListSession<TAuthClient extends AuthClient = AuthClient> = NonNullable<ListSessionsData<TAuthClient>>[number];
|
|
7
|
+
export type ListSessionsOptions<TAuthClient extends AuthClient> = Omit<ReturnType<typeof listSessionsOptions<TAuthClient>>, "queryKey" | "queryFn">;
|
|
8
|
+
/**
|
|
9
|
+
* Query options factory for the current user's active sessions.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client.
|
|
12
|
+
* @param userId - The current signed-in user's ID. Used for cache partitioning.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listSessionsOptions<TAuthClient extends AuthClient>(authClient: TAuthClient, userId: string | undefined, params?: ListSessionsParams<TAuthClient>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<InferData<TAuthClient["listSessions"]>, BetterFetchError, InferData<TAuthClient["listSessions"]>, readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null]>, "queryFn"> & {
|
|
16
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<InferData<TAuthClient["listSessions"]>, readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null], never> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
queryKey: readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null] & {
|
|
19
|
+
[dataTagSymbol]: InferData<TAuthClient["listSessions"]>;
|
|
20
|
+
[dataTagErrorSymbol]: BetterFetchError;
|
|
21
|
+
};
|
|
22
|
+
}) & {
|
|
23
|
+
queryKey: DataTag<readonly ["auth", "user", string | undefined, "listSessions", Record<string, any> | null], InferData<TAuthClient["listSessions"]>, BetterFetchError>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get the current user's active sessions from the query cache, calling
|
|
27
|
+
* `fetchListSessions` under the hood if no cached entry exists. Resolves
|
|
28
|
+
* with the session list, making it ideal for loaders or `beforeLoad` guards.
|
|
29
|
+
*
|
|
30
|
+
* @param queryClient - The React Query client.
|
|
31
|
+
* @param authClient - The Better Auth client.
|
|
32
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
33
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ensureListSessions: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListSessionsParams<TAuthClient>) => Promise<InferData<TAuthClient["listSessions"]>>;
|
|
36
|
+
/**
|
|
37
|
+
* Prefetch the current user's active sessions into the query cache. Behaves
|
|
38
|
+
* like `fetchListSessions`, but does not throw on error and does not return
|
|
39
|
+
* the data — use this to warm the cache without blocking navigation.
|
|
40
|
+
*
|
|
41
|
+
* @param queryClient - The React Query client.
|
|
42
|
+
* @param authClient - The Better Auth client.
|
|
43
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
44
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const prefetchListSessions: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListSessionsParams<TAuthClient>) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch and cache the current user's active sessions, resolving with the
|
|
49
|
+
* data or throwing on error. If a cached entry exists and is neither
|
|
50
|
+
* invalidated nor older than `staleTime`, the cached value is returned
|
|
51
|
+
* without a network call; otherwise the latest data is fetched.
|
|
52
|
+
*
|
|
53
|
+
* @param queryClient - The React Query client.
|
|
54
|
+
* @param authClient - The Better Auth client.
|
|
55
|
+
* @param userId - The signed-in user's ID, used for cache partitioning.
|
|
56
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const fetchListSessions: <TAuthClient extends AuthClient>(queryClient: QueryClient, authClient: TAuthClient, userId: string, params?: ListSessionsParams<TAuthClient>) => Promise<InferData<TAuthClient["listSessions"]>>;
|
|
59
|
+
export type UseListSessionsOptions<TAuthClient extends AuthClient> = ListSessionsOptions<TAuthClient> & ListSessionsParams<TAuthClient>;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to the current user's active sessions via TanStack Query.
|
|
62
|
+
*
|
|
63
|
+
* Shares a query key with the server-side `listSessionsOptions`, so
|
|
64
|
+
* SSR-hydrated data is reused from the cache without an immediate refetch.
|
|
65
|
+
* The query is gated on a signed-in user; while the session is loading or
|
|
66
|
+
* absent, the underlying `queryFn` is replaced with `skipToken`.
|
|
67
|
+
*
|
|
68
|
+
* @param authClient - The Better Auth client.
|
|
69
|
+
* @param options - `listSessions` params (`query`, `fetchOptions`) merged
|
|
70
|
+
* with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
|
|
71
|
+
* @param queryClient - Optional custom `QueryClient`. Defaults to the client
|
|
72
|
+
* from the nearest `QueryClientProvider`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useListSessions<TAuthClient extends AuthClient>(authClient: TAuthClient, options?: UseListSessionsOptions<TAuthClient>, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult<import('@tanstack/react-query').NoInfer<InferData<TAuthClient["listSessions"]>>, 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/settings/list-sessions-query.ts
|
|
5
|
+
function a(e, r, i) {
|
|
6
|
+
return n({
|
|
7
|
+
queryKey: t.listSessions(r, i?.query),
|
|
8
|
+
queryFn: ({ signal: t }) => e.listSessions({
|
|
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 ensureListSessions, c as fetchListSessions, a as listSessionsOptions, s as prefetchListSessions, l as useListSessions };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DataTag, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { APIError } from 'better-auth';
|
|
3
|
+
import { AuthServer } from '../../../lib/auth-server';
|
|
4
|
+
export type SessionData<TAuth extends AuthServer = AuthServer> = Awaited<ReturnType<TAuth["api"]["getSession"]>>;
|
|
5
|
+
export type Session<TAuth extends AuthServer = AuthServer> = NonNullable<SessionData<TAuth>>;
|
|
6
|
+
export type SessionParams<TAuth extends AuthServer> = Parameters<TAuth["api"]["getSession"]>[0];
|
|
7
|
+
/**
|
|
8
|
+
* Query options factory for the current session on the server.
|
|
9
|
+
*
|
|
10
|
+
* Uses the same query key as the client-side `sessionOptions` so that data
|
|
11
|
+
* fetched during SSR hydrates seamlessly into the client's React Query cache.
|
|
12
|
+
*
|
|
13
|
+
* @param auth - The Better Auth server instance.
|
|
14
|
+
* @param params - Parameters forwarded to `auth.api.getSession` (typically
|
|
15
|
+
* includes request `headers` for cookie-based session resolution).
|
|
16
|
+
*/
|
|
17
|
+
export declare function sessionOptions<TAuth extends AuthServer>(auth: TAuth, params: SessionParams<TAuth>): (import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<Awaited<ReturnType<TAuth["api"]["getSession"]>>, APIError, Awaited<ReturnType<TAuth["api"]["getSession"]>>, readonly ["auth", "getSession"]>, "queryFn"> & {
|
|
18
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<Awaited<ReturnType<TAuth["api"]["getSession"]>>, readonly ["auth", "getSession"], never> | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
queryKey: readonly ["auth", "getSession"] & {
|
|
21
|
+
[dataTagSymbol]: Awaited<ReturnType<TAuth["api"]["getSession"]>>;
|
|
22
|
+
[dataTagErrorSymbol]: APIError;
|
|
23
|
+
};
|
|
24
|
+
}) & {
|
|
25
|
+
queryKey: DataTag<readonly ["auth", "getSession"], Awaited<ReturnType<TAuth["api"]["getSession"]>>, APIError>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Get the current session from the query cache, calling `fetchSession` under
|
|
29
|
+
* the hood if no cached entry exists. Resolves with the session data, making
|
|
30
|
+
* it suitable for reading the value directly in a server component.
|
|
31
|
+
*
|
|
32
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
33
|
+
* @param auth - The Better Auth server instance.
|
|
34
|
+
* @param params - Parameters forwarded to `auth.api.getSession`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ensureSession: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, params: SessionParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["getSession"]>>>;
|
|
37
|
+
/**
|
|
38
|
+
* Prefetch the current session into the query cache. Behaves like
|
|
39
|
+
* `fetchSession`, but does not throw on error and does not return the data —
|
|
40
|
+
* use this when you only need the value to be available after hydration.
|
|
41
|
+
*
|
|
42
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
43
|
+
* @param auth - The Better Auth server instance.
|
|
44
|
+
* @param params - Parameters forwarded to `auth.api.getSession`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const prefetchSession: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, params: SessionParams<TAuth>) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch and cache the current session, resolving with the data or throwing
|
|
49
|
+
* on error. If a cached entry exists and is neither invalidated nor older
|
|
50
|
+
* than `staleTime`, the cached value is returned without a network call;
|
|
51
|
+
* otherwise the latest data is fetched.
|
|
52
|
+
*
|
|
53
|
+
* @param queryClient - The React Query client used for SSR hydration.
|
|
54
|
+
* @param auth - The Better Auth server instance.
|
|
55
|
+
* @param params - Parameters forwarded to `auth.api.getSession`.
|
|
56
|
+
*/
|
|
57
|
+
export declare const fetchSession: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, params: SessionParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["getSession"]>>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { authQueryKeys as e } from "@better-auth-ui/core";
|
|
2
|
+
import { queryOptions as t } from "@tanstack/react-query";
|
|
3
|
+
//#region src/server/queries/auth/session-query.ts
|
|
4
|
+
function n(n, r) {
|
|
5
|
+
let i = e.session;
|
|
6
|
+
return t({
|
|
7
|
+
queryKey: i,
|
|
8
|
+
queryFn: () => n.api.getSession(r)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
var r = (e, t, r) => e.ensureQueryData(n(t, r)), i = (e, t, r) => e.prefetchQuery(n(t, r)), a = (e, t, r) => e.fetchQuery(n(t, r));
|
|
12
|
+
//#endregion
|
|
13
|
+
export { r as ensureSession, a as fetchSession, i as prefetchSession, n as sessionOptions };
|