@better-auth-ui/react 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/auth/auth-provider.d.ts +4 -3
- package/dist/components/auth/auth-provider.js +24 -40
- package/dist/components/email/email-changed.d.ts +2 -2
- package/dist/components/email/email-changed.js +154 -68
- package/dist/components/email/email-localization.js +18 -23
- package/dist/components/email/email-styles.js +52 -77
- package/dist/components/email/email-verification.d.ts +2 -2
- package/dist/components/email/email-verification.js +138 -73
- package/dist/components/email/index.d.ts +9 -9
- package/dist/components/email/index.js +9 -9
- package/dist/components/email/magic-link.d.ts +2 -2
- package/dist/components/email/magic-link.js +139 -70
- package/dist/components/email/new-device.d.ts +2 -2
- package/dist/components/email/new-device.js +221 -88
- package/dist/components/email/otp-email.d.ts +2 -2
- package/dist/components/email/otp-email.js +127 -63
- package/dist/components/email/password-changed.d.ts +2 -2
- package/dist/components/email/password-changed.js +157 -74
- package/dist/components/email/reset-password.d.ts +2 -2
- package/dist/components/email/reset-password.js +138 -66
- package/dist/components/icons/apple.d.ts +1 -1
- package/dist/components/icons/apple.js +16 -9
- package/dist/components/icons/atlassian.d.ts +1 -1
- package/dist/components/icons/atlassian.js +38 -13
- package/dist/components/icons/cognito.d.ts +1 -1
- package/dist/components/icons/cognito.js +19 -9
- package/dist/components/icons/discord.d.ts +1 -1
- package/dist/components/icons/discord.js +16 -9
- package/dist/components/icons/dropbox.d.ts +1 -1
- package/dist/components/icons/dropbox.js +16 -9
- package/dist/components/icons/facebook.d.ts +1 -1
- package/dist/components/icons/facebook.js +19 -11
- package/dist/components/icons/figma.d.ts +1 -1
- package/dist/components/icons/figma.js +34 -12
- package/dist/components/icons/github.d.ts +1 -1
- package/dist/components/icons/github.js +16 -11
- package/dist/components/icons/gitlab.d.ts +1 -1
- package/dist/components/icons/gitlab.js +30 -9
- package/dist/components/icons/google.d.ts +1 -1
- package/dist/components/icons/google.js +39 -9
- package/dist/components/icons/huggingface.d.ts +1 -1
- package/dist/components/icons/huggingface.js +38 -9
- package/dist/components/icons/index.d.ts +35 -35
- package/dist/components/icons/index.js +35 -35
- package/dist/components/icons/kakao.d.ts +1 -1
- package/dist/components/icons/kakao.js +16 -11
- package/dist/components/icons/kick.d.ts +1 -1
- package/dist/components/icons/kick.js +20 -11
- package/dist/components/icons/line.d.ts +1 -1
- package/dist/components/icons/line.js +16 -9
- package/dist/components/icons/linear.d.ts +1 -1
- package/dist/components/icons/linear.js +16 -9
- package/dist/components/icons/linkedin.d.ts +1 -1
- package/dist/components/icons/linkedin.js +33 -9
- package/dist/components/icons/microsoft.d.ts +1 -1
- package/dist/components/icons/microsoft.js +30 -9
- package/dist/components/icons/naver.d.ts +1 -1
- package/dist/components/icons/naver.js +16 -9
- package/dist/components/icons/notion.d.ts +1 -1
- package/dist/components/icons/notion.js +16 -9
- package/dist/components/icons/paybin.d.ts +1 -1
- package/dist/components/icons/paybin.js +32 -8
- package/dist/components/icons/paypal.d.ts +1 -1
- package/dist/components/icons/paypal.js +30 -9
- package/dist/components/icons/polar.d.ts +1 -1
- package/dist/components/icons/polar.js +24 -9
- package/dist/components/icons/railway.d.ts +1 -1
- package/dist/components/icons/railway.js +16 -9
- package/dist/components/icons/reddit.d.ts +1 -1
- package/dist/components/icons/reddit.js +21 -9
- package/dist/components/icons/roblox.d.ts +1 -1
- package/dist/components/icons/roblox.js +17 -12
- package/dist/components/icons/salesforce.d.ts +1 -1
- package/dist/components/icons/salesforce.js +16 -9
- package/dist/components/icons/slack.d.ts +1 -1
- package/dist/components/icons/slack.js +30 -9
- package/dist/components/icons/spotify.d.ts +1 -1
- package/dist/components/icons/spotify.js +16 -9
- package/dist/components/icons/tiktok.d.ts +1 -1
- package/dist/components/icons/tiktok.js +23 -10
- package/dist/components/icons/twitch.d.ts +1 -1
- package/dist/components/icons/twitch.js +43 -12
- package/dist/components/icons/vercel.d.ts +1 -1
- package/dist/components/icons/vercel.js +16 -9
- package/dist/components/icons/vk.d.ts +1 -1
- package/dist/components/icons/vk.js +16 -9
- package/dist/components/icons/wechat.d.ts +1 -1
- package/dist/components/icons/wechat.js +16 -9
- package/dist/components/icons/x.d.ts +1 -1
- package/dist/components/icons/x.js +16 -9
- package/dist/components/icons/zoom.d.ts +1 -1
- package/dist/components/icons/zoom.js +69 -11
- package/dist/components/settings/account/theme-preview.js +286 -7
- package/dist/core.d.ts +1 -1
- package/dist/hooks/auth/use-authenticate.d.ts +30 -6
- package/dist/hooks/auth/use-authenticate.js +22 -27
- package/dist/hooks/auth/use-is-username-available.d.ts +20 -0
- package/dist/hooks/auth/use-is-username-available.js +13 -0
- package/dist/hooks/auth/use-request-password-reset.d.ts +12 -17
- package/dist/hooks/auth/use-request-password-reset.js +12 -13
- package/dist/hooks/auth/use-reset-password.d.ts +14 -31
- package/dist/hooks/auth/use-reset-password.js +12 -12
- package/dist/hooks/auth/use-send-verification-email.d.ts +11 -16
- package/dist/hooks/auth/use-send-verification-email.js +12 -12
- package/dist/hooks/auth/use-session.d.ts +31 -5
- package/dist/hooks/auth/use-session.js +15 -17
- package/dist/hooks/auth/use-sign-in-email.d.ts +12 -39
- package/dist/hooks/auth/use-sign-in-email.js +16 -24
- package/dist/hooks/auth/use-sign-in-magic-link.d.ts +15 -20
- package/dist/hooks/auth/use-sign-in-magic-link.js +12 -12
- package/dist/hooks/auth/use-sign-in-passkey.d.ts +13 -50
- package/dist/hooks/auth/use-sign-in-passkey.js +16 -24
- package/dist/hooks/auth/use-sign-in-social.d.ts +32 -62
- package/dist/hooks/auth/use-sign-in-social.js +12 -12
- package/dist/hooks/auth/use-sign-in-username.d.ts +25 -0
- package/dist/hooks/auth/use-sign-in-username.js +17 -0
- package/dist/hooks/auth/use-sign-out.d.ts +11 -12
- package/dist/hooks/auth/use-sign-out.js +15 -23
- package/dist/hooks/auth/use-sign-up-email.d.ts +178 -262
- package/dist/hooks/auth/use-sign-up-email.js +16 -24
- package/dist/hooks/auth/use-user.d.ts +63 -61
- package/dist/hooks/auth/use-user.js +10 -13
- package/dist/hooks/settings/use-account-info.d.ts +12 -12
- package/dist/hooks/settings/use-account-info.js +17 -24
- package/dist/hooks/settings/use-add-passkey.d.ts +11 -33
- package/dist/hooks/settings/use-add-passkey.js +16 -23
- package/dist/hooks/settings/use-change-email.d.ts +12 -15
- package/dist/hooks/settings/use-change-email.js +16 -22
- package/dist/hooks/settings/use-change-password.d.ts +12 -45
- package/dist/hooks/settings/use-change-password.js +12 -10
- package/dist/hooks/settings/use-delete-passkey.d.ts +11 -13
- package/dist/hooks/settings/use-delete-passkey.js +16 -23
- package/dist/hooks/settings/use-delete-user.d.ts +14 -32
- package/dist/hooks/settings/use-delete-user.js +12 -10
- package/dist/hooks/settings/use-link-social.d.ts +23 -26
- package/dist/hooks/settings/use-link-social.js +12 -9
- package/dist/hooks/settings/use-list-accounts.d.ts +10 -8
- package/dist/hooks/settings/use-list-accounts.js +14 -22
- package/dist/hooks/settings/use-list-device-sessions.d.ts +30 -7
- package/dist/hooks/settings/use-list-device-sessions.js +14 -21
- package/dist/hooks/settings/use-list-sessions.d.ts +10 -7
- package/dist/hooks/settings/use-list-sessions.js +14 -21
- package/dist/hooks/settings/use-list-user-passkeys.d.ts +9 -6
- package/dist/hooks/settings/use-list-user-passkeys.js +14 -21
- package/dist/hooks/settings/use-revoke-multi-session.d.ts +12 -12
- package/dist/hooks/settings/use-revoke-multi-session.js +16 -19
- package/dist/hooks/settings/use-revoke-session.d.ts +12 -12
- package/dist/hooks/settings/use-revoke-session.js +16 -20
- package/dist/hooks/settings/use-set-active-session.d.ts +13 -30
- package/dist/hooks/settings/use-set-active-session.js +19 -27
- package/dist/hooks/settings/use-unlink-account.d.ts +13 -13
- package/dist/hooks/settings/use-unlink-account.js +16 -20
- package/dist/hooks/settings/use-update-user.d.ts +1179 -5
- package/dist/hooks/settings/use-update-user.js +23 -28
- package/dist/hooks/use-auth-mutation.d.ts +12 -0
- package/dist/hooks/use-auth-mutation.js +11 -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 +40 -36
- package/dist/index.js +84 -36
- package/dist/lib/auth-client.d.ts +1254 -1254
- package/dist/lib/auth-client.js +11 -11
- package/dist/lib/auth-config.d.ts +3 -3
- package/dist/lib/auth-context.d.ts +2 -2
- package/dist/lib/auth-context.js +5 -2
- package/dist/lib/provider-icons.d.ts +2 -2
- package/dist/lib/provider-icons.js +75 -47
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +7 -4
- package/dist/mutations/auth/is-username-available-options.d.ts +19 -0
- package/dist/mutations/auth/is-username-available-options.js +7 -0
- package/dist/mutations/auth/request-password-reset-options.d.ts +15 -0
- package/dist/mutations/auth/request-password-reset-options.js +7 -0
- package/dist/mutations/auth/reset-password-options.d.ts +17 -0
- package/dist/mutations/auth/reset-password-options.js +7 -0
- package/dist/mutations/auth/send-verification-email-options.d.ts +15 -0
- package/dist/mutations/auth/send-verification-email-options.js +7 -0
- package/dist/mutations/auth/sign-in-email-options.d.ts +23 -0
- package/dist/mutations/auth/sign-in-email-options.js +11 -0
- package/dist/mutations/auth/sign-in-magic-link-options.d.ts +23 -0
- package/dist/mutations/auth/sign-in-magic-link-options.js +11 -0
- package/dist/mutations/auth/sign-in-passkey-options.d.ts +15 -0
- package/dist/mutations/auth/sign-in-passkey-options.js +11 -0
- package/dist/mutations/auth/sign-in-social-options.d.ts +61 -0
- package/dist/mutations/auth/sign-in-social-options.js +11 -0
- package/dist/mutations/auth/sign-in-username-options.d.ts +19 -0
- package/dist/mutations/auth/sign-in-username-options.js +11 -0
- package/dist/mutations/auth/sign-out-options.d.ts +12 -0
- package/dist/mutations/auth/sign-out-options.js +7 -0
- package/dist/mutations/auth/sign-up-email-options.d.ts +1180 -0
- package/dist/mutations/auth/sign-up-email-options.js +11 -0
- package/dist/mutations/auth-mutation-options.d.ts +25 -0
- package/dist/mutations/auth-mutation-options.js +19 -0
- package/dist/mutations/settings/add-passkey-options.d.ts +15 -0
- package/dist/mutations/settings/add-passkey-options.js +11 -0
- package/dist/mutations/settings/change-email-options.d.ts +15 -0
- package/dist/mutations/settings/change-email-options.js +7 -0
- package/dist/mutations/settings/change-password-options.d.ts +17 -0
- package/dist/mutations/settings/change-password-options.js +7 -0
- package/dist/mutations/settings/delete-passkey-options.d.ts +13 -0
- package/dist/mutations/settings/delete-passkey-options.js +11 -0
- package/dist/mutations/settings/delete-user-options.d.ts +20 -0
- package/dist/mutations/settings/delete-user-options.js +7 -0
- package/dist/mutations/settings/link-social-options.d.ts +39 -0
- package/dist/mutations/settings/link-social-options.js +7 -0
- package/dist/mutations/settings/revoke-multi-session-options.d.ts +13 -0
- package/dist/mutations/settings/revoke-multi-session-options.js +11 -0
- package/dist/mutations/settings/revoke-session-options.d.ts +13 -0
- package/dist/mutations/settings/revoke-session-options.js +7 -0
- package/dist/mutations/settings/set-active-session-options.d.ts +13 -0
- package/dist/mutations/settings/set-active-session-options.js +11 -0
- package/dist/mutations/settings/unlink-account-options.d.ts +15 -0
- package/dist/mutations/settings/unlink-account-options.js +7 -0
- package/dist/mutations/settings/update-user-options.d.ts +1182 -0
- package/dist/mutations/settings/update-user-options.js +7 -0
- package/dist/queries/auth/session-options.d.ts +110 -0
- package/dist/queries/auth/session-options.js +7 -0
- package/dist/queries/auth-query-options.d.ts +29 -0
- package/dist/queries/auth-query-options.js +17 -0
- package/dist/queries/settings/account-info-options.d.ts +32 -0
- package/dist/queries/settings/account-info-options.js +12 -0
- package/dist/queries/settings/list-accounts-options.d.ts +53 -0
- package/dist/queries/settings/list-accounts-options.js +12 -0
- package/dist/queries/settings/list-device-sessions-options.d.ts +99 -0
- package/dist/queries/settings/list-device-sessions-options.js +12 -0
- package/dist/queries/settings/list-sessions-options.d.ts +54 -0
- package/dist/queries/settings/list-sessions-options.js +12 -0
- package/dist/queries/settings/list-user-passkeys-options.d.ts +18 -0
- package/dist/queries/settings/list-user-passkeys-options.js +12 -0
- package/package.json +11 -11
- package/src/components/auth/auth-provider.tsx +4 -6
- package/src/hooks/auth/use-authenticate.ts +8 -9
- package/src/hooks/auth/use-is-username-available.ts +31 -0
- package/src/hooks/auth/use-request-password-reset.ts +20 -11
- package/src/hooks/auth/use-reset-password.ts +20 -12
- package/src/hooks/auth/use-send-verification-email.ts +19 -11
- package/src/hooks/auth/use-session.ts +22 -17
- package/src/hooks/auth/use-sign-in-email.ts +24 -19
- package/src/hooks/auth/use-sign-in-magic-link.ts +19 -13
- package/src/hooks/auth/use-sign-in-passkey.ts +24 -18
- package/src/hooks/auth/use-sign-in-social.ts +19 -11
- package/src/hooks/auth/use-sign-in-username.ts +40 -0
- package/src/hooks/auth/use-sign-out.ts +20 -20
- package/src/hooks/auth/use-sign-up-email.ts +25 -21
- package/src/hooks/auth/use-user.ts +7 -9
- package/src/hooks/settings/use-account-info.ts +31 -21
- package/src/hooks/settings/use-add-passkey.ts +22 -17
- package/src/hooks/settings/use-change-email.ts +24 -20
- package/src/hooks/settings/use-change-password.ts +19 -11
- package/src/hooks/settings/use-delete-passkey.ts +21 -16
- package/src/hooks/settings/use-delete-user.ts +19 -11
- package/src/hooks/settings/use-link-social.ts +20 -10
- package/src/hooks/settings/use-list-accounts.ts +28 -16
- package/src/hooks/settings/use-list-device-sessions.ts +29 -22
- package/src/hooks/settings/use-list-sessions.ts +28 -15
- package/src/hooks/settings/use-list-user-passkeys.ts +28 -17
- package/src/hooks/settings/use-revoke-multi-session.ts +28 -19
- package/src/hooks/settings/use-revoke-session.ts +26 -18
- package/src/hooks/settings/use-set-active-session.ts +40 -28
- package/src/hooks/settings/use-unlink-account.ts +23 -17
- package/src/hooks/settings/use-update-user.ts +33 -27
- package/src/hooks/use-auth-mutation.ts +29 -0
- package/src/hooks/use-auth-query.ts +36 -0
- package/src/index.ts +4 -0
- package/src/lib/auth-config.ts +1 -1
- package/src/mutations/auth/is-username-available-options.ts +18 -0
- package/src/mutations/auth/request-password-reset-options.ts +14 -0
- package/src/mutations/auth/reset-password-options.ts +14 -0
- package/src/mutations/auth/send-verification-email-options.ts +14 -0
- package/src/mutations/auth/sign-in-email-options.ts +19 -0
- package/src/mutations/auth/sign-in-magic-link-options.ts +15 -0
- package/src/mutations/auth/sign-in-passkey-options.ts +15 -0
- package/src/mutations/auth/sign-in-social-options.ts +19 -0
- package/src/mutations/auth/sign-in-username-options.ts +15 -0
- package/src/mutations/auth/sign-out-options.ts +11 -0
- package/src/mutations/auth/sign-up-email-options.ts +15 -0
- package/src/mutations/auth-mutation-options.ts +49 -0
- package/src/mutations/settings/add-passkey-options.ts +15 -0
- package/src/mutations/settings/change-email-options.ts +11 -0
- package/src/mutations/settings/change-password-options.ts +14 -0
- package/src/mutations/settings/delete-passkey-options.ts +15 -0
- package/src/mutations/settings/delete-user-options.ts +11 -0
- package/src/mutations/settings/link-social-options.ts +11 -0
- package/src/mutations/settings/revoke-multi-session-options.ts +15 -0
- package/src/mutations/settings/revoke-session-options.ts +14 -0
- package/src/mutations/settings/set-active-session-options.ts +15 -0
- package/src/mutations/settings/unlink-account-options.ts +14 -0
- package/src/mutations/settings/update-user-options.ts +15 -0
- package/src/queries/auth/session-options.ts +18 -0
- package/src/queries/auth-query-options.ts +34 -0
- package/src/queries/settings/account-info-options.ts +25 -0
- package/src/queries/settings/list-accounts-options.ts +26 -0
- package/src/queries/settings/list-device-sessions-options.ts +24 -0
- package/src/queries/settings/list-sessions-options.ts +23 -0
- package/src/queries/settings/list-user-passkeys-options.ts +23 -0
- package/dist/hooks/auth/use-auth-mutation.d.ts +0 -18
- package/dist/hooks/auth/use-auth-mutation.js +0 -10
- package/dist/hooks/auth/use-auth-query.d.ts +0 -24
- package/dist/hooks/auth/use-auth-query.js +0 -10
- package/dist/lib/auth-config.js +0 -1
- package/src/hooks/auth/use-auth-mutation.ts +0 -56
- package/src/hooks/auth/use-auth-query.ts +0 -50
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { requestPasswordResetOptions } from "../../mutations/auth/request-password-reset-options"
|
|
6
|
+
|
|
7
|
+
export type UseRequestPasswordResetParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["requestPasswordReset"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseRequestPasswordResetOptions = Omit<
|
|
12
|
+
ReturnType<typeof requestPasswordResetOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Hook that creates a mutation for the forgot-password flow.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
* and navigates to the sign-in view on success.
|
|
19
|
+
* Sends a password reset email for the provided address.
|
|
15
20
|
*
|
|
21
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
16
22
|
* @returns The `useMutation` result.
|
|
17
23
|
*/
|
|
18
24
|
export function useRequestPasswordReset(
|
|
19
|
-
options?:
|
|
25
|
+
options?: UseRequestPasswordResetOptions
|
|
20
26
|
) {
|
|
21
27
|
const { authClient } = useAuth()
|
|
22
28
|
|
|
23
|
-
return
|
|
29
|
+
return useMutation({
|
|
30
|
+
...requestPasswordResetOptions(authClient),
|
|
31
|
+
...options
|
|
32
|
+
})
|
|
24
33
|
}
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { resetPasswordOptions } from "../../mutations/auth/reset-password-options"
|
|
6
|
+
|
|
7
|
+
export type UseResetPasswordParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["resetPassword"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseResetPasswordOptions = Omit<
|
|
12
|
+
ReturnType<typeof resetPasswordOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Hook that creates a mutation for the reset-password flow.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
19
|
+
* Resets the user's password using the provided token and new password.
|
|
14
20
|
*
|
|
21
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
15
22
|
* @returns The `useMutation` result.
|
|
16
23
|
*/
|
|
17
|
-
export function useResetPassword(
|
|
18
|
-
options?: UseAuthMutationOptions<AuthClient["resetPassword"]>
|
|
19
|
-
) {
|
|
24
|
+
export function useResetPassword(options?: UseResetPasswordOptions) {
|
|
20
25
|
const { authClient } = useAuth()
|
|
21
26
|
|
|
22
|
-
return
|
|
27
|
+
return useMutation({
|
|
28
|
+
...resetPasswordOptions(authClient),
|
|
29
|
+
...options
|
|
30
|
+
})
|
|
23
31
|
}
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { sendVerificationEmailOptions } from "../../mutations/auth/send-verification-email-options"
|
|
6
|
+
|
|
7
|
+
export type UseSendVerificationEmailParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["sendVerificationEmail"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseSendVerificationEmailOptions = Omit<
|
|
12
|
+
ReturnType<typeof sendVerificationEmailOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Hook that creates a mutation to send a verification email.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
15
20
|
* @returns The `useMutation` result.
|
|
16
21
|
*/
|
|
17
22
|
export function useSendVerificationEmail(
|
|
18
|
-
options?:
|
|
23
|
+
options?: UseSendVerificationEmailOptions
|
|
19
24
|
) {
|
|
20
25
|
const { authClient } = useAuth()
|
|
21
26
|
|
|
22
|
-
return
|
|
27
|
+
return useMutation({
|
|
28
|
+
...sendVerificationEmailOptions(authClient),
|
|
29
|
+
...options
|
|
30
|
+
})
|
|
23
31
|
}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
3
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
4
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
5
|
+
|
|
6
|
+
export type UseSessionParams = NonNullable<
|
|
7
|
+
Parameters<AuthClient["getSession"]>[0]
|
|
8
|
+
>
|
|
9
|
+
|
|
10
|
+
export type UseSessionOptions = Omit<
|
|
11
|
+
ReturnType<typeof sessionOptions>,
|
|
12
|
+
"queryKey" | "queryFn"
|
|
13
|
+
> &
|
|
14
|
+
UseSessionParams
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Retrieve the current authentication session.
|
|
10
18
|
*
|
|
11
|
-
* @param options -
|
|
12
|
-
*
|
|
19
|
+
* @param options - Better Auth params (`query`, `fetchOptions`) and React
|
|
20
|
+
* Query options forwarded to `useQuery`.
|
|
21
|
+
* @returns React Query result for the session.
|
|
13
22
|
*/
|
|
14
|
-
export function useSession(
|
|
15
|
-
options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
|
|
16
|
-
): UseAuthQueryResult<AuthClient["getSession"]> {
|
|
23
|
+
export function useSession(options?: UseSessionOptions) {
|
|
17
24
|
const { authClient } = useAuth()
|
|
25
|
+
const { query, fetchOptions, ...queryOptions } = options ?? {}
|
|
18
26
|
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
queryKey: ["auth", "getSession"],
|
|
23
|
-
...options
|
|
24
|
-
}
|
|
27
|
+
return useQuery({
|
|
28
|
+
...sessionOptions(authClient, { query, fetchOptions }),
|
|
29
|
+
...queryOptions
|
|
25
30
|
})
|
|
26
31
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
import
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signInEmailOptions } from "../../mutations/auth/sign-in-email-options"
|
|
6
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
9
7
|
|
|
10
|
-
export
|
|
8
|
+
export type UseSignInEmailParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["signIn"]["email"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseSignInEmailOptions = Omit<
|
|
13
|
+
ReturnType<typeof signInEmailOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Hook that creates a mutation for email/password sign-in.
|
|
@@ -15,22 +20,22 @@ export { useAuthMutation } from "./use-auth-mutation"
|
|
|
15
20
|
* The mutation sends an email/password sign-in request and
|
|
16
21
|
* refetches the session on completion.
|
|
17
22
|
*
|
|
23
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
18
24
|
* @returns The `useMutation` result.
|
|
19
25
|
*/
|
|
20
|
-
export function useSignInEmail(
|
|
21
|
-
options?: UseAuthMutationOptions<AuthClient["signIn"]["email"]>
|
|
22
|
-
) {
|
|
26
|
+
export function useSignInEmail(options?: UseSignInEmailOptions) {
|
|
23
27
|
const { authClient } = useAuth()
|
|
24
28
|
const queryClient = useQueryClient()
|
|
25
29
|
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
options
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
return useMutation({
|
|
31
|
+
...signInEmailOptions(authClient),
|
|
32
|
+
...options,
|
|
33
|
+
onSuccess: async (...args) => {
|
|
34
|
+
queryClient.resetQueries({
|
|
35
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
await options?.onSuccess?.(...args)
|
|
34
39
|
}
|
|
35
40
|
})
|
|
36
41
|
}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signInMagicLinkOptions } from "../../mutations/auth/sign-in-magic-link-options"
|
|
6
|
+
|
|
7
|
+
export type UseSignInMagicLinkParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["signIn"]["magicLink"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseSignInMagicLinkOptions = Omit<
|
|
12
|
+
ReturnType<typeof signInMagicLinkOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Hook that creates a mutation for magic-link sign-in.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
15
20
|
* @returns The `useMutation` result.
|
|
16
21
|
*/
|
|
17
|
-
export function useSignInMagicLink(
|
|
18
|
-
options?: UseAuthMutationOptions<AuthClient["signIn"]["magicLink"]>
|
|
19
|
-
) {
|
|
22
|
+
export function useSignInMagicLink(options?: UseSignInMagicLinkOptions) {
|
|
20
23
|
const { authClient } = useAuth()
|
|
21
24
|
|
|
22
|
-
return
|
|
25
|
+
return useMutation({
|
|
26
|
+
...signInMagicLinkOptions(authClient),
|
|
27
|
+
...options
|
|
28
|
+
})
|
|
23
29
|
}
|
|
@@ -1,34 +1,40 @@
|
|
|
1
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
2
2
|
|
|
3
3
|
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
4
|
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { signInPasskeyOptions } from "../../mutations/auth/sign-in-passkey-options"
|
|
6
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
7
|
+
|
|
8
|
+
export type UseSignInPasskeyParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["signIn"]["passkey"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseSignInPasskeyOptions = Omit<
|
|
13
|
+
ReturnType<typeof signInPasskeyOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
18
|
* Hook that creates a mutation for passkey sign-in.
|
|
12
19
|
*
|
|
13
|
-
*
|
|
14
|
-
* refetches the session on completion.
|
|
20
|
+
* Resets the session query on completion so the new session is refetched.
|
|
15
21
|
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
16
23
|
* @returns The `useMutation` result.
|
|
17
24
|
*/
|
|
18
|
-
export function useSignInPasskey(
|
|
19
|
-
options?: UseAuthMutationOptions<AuthClient["signIn"]["passkey"]>
|
|
20
|
-
) {
|
|
25
|
+
export function useSignInPasskey(options?: UseSignInPasskeyOptions) {
|
|
21
26
|
const { authClient } = useAuth()
|
|
22
27
|
const queryClient = useQueryClient()
|
|
23
28
|
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
options
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
return useMutation({
|
|
30
|
+
...signInPasskeyOptions(authClient),
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (...args) => {
|
|
33
|
+
queryClient.resetQueries({
|
|
34
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await options?.onSuccess?.(...args)
|
|
32
38
|
}
|
|
33
39
|
})
|
|
34
40
|
}
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signInSocialOptions } from "../../mutations/auth/sign-in-social-options"
|
|
6
|
+
|
|
7
|
+
export type UseSignInSocialParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["signIn"]["social"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseSignInSocialOptions = Omit<
|
|
12
|
+
ReturnType<typeof signInSocialOptions>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Hook that creates a mutation for social sign-in.
|
|
12
18
|
*
|
|
13
19
|
* The mutation initiates a social sign-in flow with the specified provider.
|
|
14
20
|
*
|
|
21
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
15
22
|
* @returns The `useMutation` result.
|
|
16
23
|
*/
|
|
17
|
-
export function useSignInSocial(
|
|
18
|
-
options?: UseAuthMutationOptions<AuthClient["signIn"]["social"]>
|
|
19
|
-
) {
|
|
24
|
+
export function useSignInSocial(options?: UseSignInSocialOptions) {
|
|
20
25
|
const { authClient } = useAuth()
|
|
21
26
|
|
|
22
|
-
return
|
|
27
|
+
return useMutation({
|
|
28
|
+
...signInSocialOptions(authClient),
|
|
29
|
+
...options
|
|
30
|
+
})
|
|
23
31
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signInUsernameOptions } from "../../mutations/auth/sign-in-username-options"
|
|
6
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
7
|
+
|
|
8
|
+
export type UseSignInUsernameParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["signIn"]["username"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseSignInUsernameOptions = Omit<
|
|
13
|
+
ReturnType<typeof signInUsernameOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hook that creates a mutation for username/password sign-in.
|
|
19
|
+
*
|
|
20
|
+
* Resets the session query on completion so the new session is refetched.
|
|
21
|
+
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
23
|
+
* @returns The `useMutation` result.
|
|
24
|
+
*/
|
|
25
|
+
export function useSignInUsername(options?: UseSignInUsernameOptions) {
|
|
26
|
+
const { authClient } = useAuth()
|
|
27
|
+
const queryClient = useQueryClient()
|
|
28
|
+
|
|
29
|
+
return useMutation({
|
|
30
|
+
...signInUsernameOptions(authClient),
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (...args) => {
|
|
33
|
+
queryClient.resetQueries({
|
|
34
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await options?.onSuccess?.(...args)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
7
|
-
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
8
2
|
|
|
9
|
-
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signOutOptions } from "../../mutations/auth/sign-out-options"
|
|
6
|
+
|
|
7
|
+
export type UseSignOutParams = NonNullable<Parameters<AuthClient["signOut"]>[0]>
|
|
8
|
+
|
|
9
|
+
export type UseSignOutOptions = Omit<
|
|
10
|
+
ReturnType<typeof signOutOptions>,
|
|
11
|
+
"mutationKey" | "mutationFn"
|
|
12
|
+
>
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Hook that creates a mutation for signing out.
|
|
13
16
|
*
|
|
14
|
-
*
|
|
17
|
+
* Removes all cached auth queries on completion.
|
|
15
18
|
*
|
|
19
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
16
20
|
* @returns The `useMutation` result.
|
|
17
21
|
*/
|
|
18
|
-
export function useSignOut(
|
|
19
|
-
options?: UseAuthMutationOptions<AuthClient["signOut"]>
|
|
20
|
-
) {
|
|
22
|
+
export function useSignOut(options?: UseSignOutOptions) {
|
|
21
23
|
const { authClient } = useAuth()
|
|
22
24
|
const queryClient = useQueryClient()
|
|
23
25
|
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
options
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await options?.onSuccess?.(...args)
|
|
31
|
-
}
|
|
26
|
+
return useMutation({
|
|
27
|
+
...signOutOptions(authClient),
|
|
28
|
+
...options,
|
|
29
|
+
onSuccess: async (...args) => {
|
|
30
|
+
queryClient.removeQueries({ queryKey: ["auth"] })
|
|
31
|
+
await options?.onSuccess?.(...args)
|
|
32
32
|
}
|
|
33
33
|
})
|
|
34
34
|
}
|
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthClient,
|
|
3
|
-
useAuth,
|
|
4
|
-
useAuthMutation
|
|
5
|
-
} from "@better-auth-ui/react"
|
|
6
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
7
2
|
|
|
8
|
-
import
|
|
3
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
4
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
5
|
+
import { signUpEmailOptions } from "../../mutations/auth/sign-up-email-options"
|
|
6
|
+
import { sessionOptions } from "../../queries/auth/session-options"
|
|
9
7
|
|
|
10
|
-
export
|
|
8
|
+
export type UseSignUpEmailParams = NonNullable<
|
|
9
|
+
Parameters<AuthClient["signUp"]["email"]>[0]
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
export type UseSignUpEmailOptions = Omit<
|
|
13
|
+
ReturnType<typeof signUpEmailOptions>,
|
|
14
|
+
"mutationKey" | "mutationFn"
|
|
15
|
+
>
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Hook that creates a mutation for email/password sign-up.
|
|
14
19
|
*
|
|
15
|
-
*
|
|
16
|
-
* refetches the session on success.
|
|
20
|
+
* Resets the session query on success so the new session is refetched.
|
|
17
21
|
*
|
|
22
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
18
23
|
* @returns The `useMutation` result.
|
|
19
24
|
*/
|
|
20
|
-
export function useSignUpEmail(
|
|
21
|
-
options?: UseAuthMutationOptions<AuthClient["signUp"]["email"]>
|
|
22
|
-
) {
|
|
25
|
+
export function useSignUpEmail(options?: UseSignUpEmailOptions) {
|
|
23
26
|
const { authClient } = useAuth()
|
|
24
27
|
const queryClient = useQueryClient()
|
|
25
28
|
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
options
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
return useMutation({
|
|
30
|
+
...signUpEmailOptions(authClient),
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (...args) => {
|
|
33
|
+
queryClient.resetQueries({
|
|
34
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await options?.onSuccess?.(...args)
|
|
34
38
|
}
|
|
35
39
|
})
|
|
36
40
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { UseAuthQueryOptions } from "./use-auth-query"
|
|
3
|
-
|
|
4
|
-
import { useSession } from "./use-session"
|
|
1
|
+
import { type UseSessionOptions, useSession } from "./use-session"
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* Retrieve the current authenticated user.
|
|
8
5
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Thin wrapper over `useSession` that returns `session.user` as `data`.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Better Auth params (`query`, `fetchOptions`) and React
|
|
9
|
+
* Query options forwarded to `useQuery`.
|
|
10
|
+
* @returns React Query result with `data` narrowed to the user object.
|
|
11
11
|
*/
|
|
12
|
-
export function useUser(
|
|
13
|
-
options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
|
|
14
|
-
) {
|
|
12
|
+
export function useUser(options?: UseSessionOptions) {
|
|
15
13
|
const { data, ...rest } = useSession(options)
|
|
16
14
|
|
|
17
15
|
return {
|
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { skipToken, useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { useAuth } from "../../components/auth/auth-provider"
|
|
3
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
4
|
+
import { accountInfoOptions } from "../../queries/settings/account-info-options"
|
|
5
|
+
import { useSession } from "../auth/use-session"
|
|
6
|
+
|
|
7
|
+
export type UseAccountInfoParams = NonNullable<
|
|
8
|
+
Parameters<AuthClient["accountInfo"]>[0]
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
export type UseAccountInfoOptions = Omit<
|
|
12
|
+
ReturnType<typeof accountInfoOptions>,
|
|
13
|
+
"queryKey" | "queryFn"
|
|
14
|
+
> &
|
|
15
|
+
UseAccountInfoParams
|
|
3
16
|
|
|
4
17
|
/**
|
|
5
|
-
* Retrieve provider-specific
|
|
18
|
+
* Retrieve provider-specific info for a linked account.
|
|
6
19
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* from the account ID.
|
|
20
|
+
* Keyed per-user; waits for the active session and `options.query.accountId`
|
|
21
|
+
* before firing.
|
|
10
22
|
*
|
|
11
|
-
* @param
|
|
12
|
-
*
|
|
13
|
-
* @returns The react-query result containing account info data, loading state, and error state
|
|
23
|
+
* @param options - Better Auth params (`query`, `fetchOptions`) and React
|
|
24
|
+
* Query options forwarded to `useQuery`.
|
|
14
25
|
*/
|
|
15
|
-
export function useAccountInfo(
|
|
16
|
-
accountId?: string,
|
|
17
|
-
options?: Partial<UseAuthQueryOptions<AuthClient["accountInfo"]>>
|
|
18
|
-
) {
|
|
26
|
+
export function useAccountInfo(options?: UseAccountInfoOptions) {
|
|
19
27
|
const { authClient } = useAuth()
|
|
28
|
+
const { data: session } = useSession({ refetchOnMount: false })
|
|
29
|
+
const userId = session?.user.id
|
|
30
|
+
|
|
31
|
+
const { query, fetchOptions, ...queryOptions } = options ?? {}
|
|
32
|
+
const accountId = query?.accountId
|
|
33
|
+
const disabled = !userId || !accountId
|
|
20
34
|
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
queryKey: ["auth", "accountInfo", accountId],
|
|
26
|
-
enabled: !!accountId,
|
|
27
|
-
...options
|
|
28
|
-
}
|
|
35
|
+
return useQuery({
|
|
36
|
+
...accountInfoOptions(authClient, userId, { query, fetchOptions }),
|
|
37
|
+
...(disabled && { queryFn: skipToken }),
|
|
38
|
+
...queryOptions
|
|
29
39
|
})
|
|
30
40
|
}
|