@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for revoking a user session.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
*/
|
|
9
|
+
export function revokeSessionOptions(authClient: AuthClient) {
|
|
10
|
+
return authMutationOptions(authClient.revokeSession, [
|
|
11
|
+
"auth",
|
|
12
|
+
"revokeSession"
|
|
13
|
+
])
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for switching the active device session.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
*/
|
|
9
|
+
export function setActiveSessionOptions(authClient: AuthClient) {
|
|
10
|
+
return authMutationOptions(authClient.multiSession.setActive, [
|
|
11
|
+
"auth",
|
|
12
|
+
"multiSession",
|
|
13
|
+
"setActive"
|
|
14
|
+
])
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for unlinking a social provider from the current user.
|
|
6
|
+
*
|
|
7
|
+
* @param authClient - The Better Auth client.
|
|
8
|
+
*/
|
|
9
|
+
export function unlinkAccountOptions(authClient: AuthClient) {
|
|
10
|
+
return authMutationOptions(authClient.unlinkAccount, [
|
|
11
|
+
"auth",
|
|
12
|
+
"unlinkAccount"
|
|
13
|
+
])
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authMutationOptions } from "../auth-mutation-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mutation options factory for updating the authenticated user's profile.
|
|
6
|
+
*
|
|
7
|
+
* The returned `mutationKey` (`["auth", "updateUser"]`) is stable and can
|
|
8
|
+
* be passed to `useIsMutating` or matched inside a global `MutationCache`
|
|
9
|
+
* observer for toast handling.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client.
|
|
12
|
+
*/
|
|
13
|
+
export function updateUserOptions(authClient: AuthClient) {
|
|
14
|
+
return authMutationOptions(authClient.updateUser, ["auth", "updateUser"])
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current session.
|
|
6
|
+
*
|
|
7
|
+
* Access `.queryKey` on the returned options for cache seeding or
|
|
8
|
+
* invalidation: `queryClient.setQueryData(sessionOptions(authClient).queryKey, session)`.
|
|
9
|
+
*
|
|
10
|
+
* @param authClient - The Better Auth client.
|
|
11
|
+
* @param params - Parameters forwarded to `authClient.getSession`.
|
|
12
|
+
*/
|
|
13
|
+
export function sessionOptions(
|
|
14
|
+
authClient: AuthClient,
|
|
15
|
+
params?: Parameters<AuthClient["getSession"]>[0]
|
|
16
|
+
) {
|
|
17
|
+
return authQueryOptions(authClient.getSession, ["auth", "getSession"], params)
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type QueryKey, queryOptions } from "@tanstack/react-query"
|
|
2
|
+
import type { BetterFetchError, BetterFetchOption } from "better-auth/client"
|
|
3
|
+
|
|
4
|
+
export type AuthFn<TData = unknown> = (params: {
|
|
5
|
+
query?: Record<string, unknown>
|
|
6
|
+
fetchOptions?: BetterFetchOption
|
|
7
|
+
}) => Promise<{ data: TData }>
|
|
8
|
+
|
|
9
|
+
type AuthFnData<TFn> = TFn extends AuthFn<infer TData> ? TData : never
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Build `queryOptions` for a Better Auth endpoint.
|
|
13
|
+
*
|
|
14
|
+
* Appends `params.query` (or `null`) to the supplied `queryKey` so cache
|
|
15
|
+
* identity tracks endpoint inputs. Wires `throw: true` and the React Query
|
|
16
|
+
* `AbortSignal` into `fetchOptions`.
|
|
17
|
+
*
|
|
18
|
+
* @param authFn - Better Auth client method (e.g. `authClient.getSession`).
|
|
19
|
+
* @param queryKey - Scope prefix for the key. `params.query` is appended automatically.
|
|
20
|
+
* @param params - Parameters forwarded to `authFn`.
|
|
21
|
+
*/
|
|
22
|
+
export function authQueryOptions<
|
|
23
|
+
TFn extends AuthFn,
|
|
24
|
+
const TQueryKey extends QueryKey
|
|
25
|
+
>(authFn: TFn, queryKey: TQueryKey, params?: Parameters<TFn>[0]) {
|
|
26
|
+
return queryOptions<AuthFnData<TFn>, BetterFetchError>({
|
|
27
|
+
queryKey: [...queryKey, params?.query ?? null] as const,
|
|
28
|
+
queryFn: ({ signal }) =>
|
|
29
|
+
authFn({
|
|
30
|
+
...params,
|
|
31
|
+
fetchOptions: { ...params?.fetchOptions, signal, throw: true }
|
|
32
|
+
}) as Promise<AuthFnData<TFn>>
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for provider-specific account info.
|
|
6
|
+
*
|
|
7
|
+
* Keyed per-user. `userId` and `params` are both optional so the factory can
|
|
8
|
+
* build stable options before either is known — the consumer swaps `queryFn`
|
|
9
|
+
* for `skipToken` until ready.
|
|
10
|
+
*
|
|
11
|
+
* @param authClient - The Better Auth client.
|
|
12
|
+
* @param userId - The current signed in user's ID.
|
|
13
|
+
* @param params - Parameters forwarded to `authClient.accountInfo`.
|
|
14
|
+
*/
|
|
15
|
+
export function accountInfoOptions(
|
|
16
|
+
authClient: AuthClient,
|
|
17
|
+
userId?: string,
|
|
18
|
+
params?: Parameters<AuthClient["accountInfo"]>[0]
|
|
19
|
+
) {
|
|
20
|
+
return authQueryOptions(
|
|
21
|
+
authClient.accountInfo,
|
|
22
|
+
["auth", "user", userId, "accountInfo"],
|
|
23
|
+
params
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for a user's linked social accounts.
|
|
6
|
+
*
|
|
7
|
+
* Keyed per-user (enables offline account switching with a persister).
|
|
8
|
+
* `userId` is optional so the factory can build stable options before the
|
|
9
|
+
* active session resolves — the consumer swaps `queryFn` for `skipToken`
|
|
10
|
+
* until ready.
|
|
11
|
+
*
|
|
12
|
+
* @param authClient - The Better Auth client.
|
|
13
|
+
* @param userId - The current signed in user's ID.
|
|
14
|
+
* @param params - Parameters forwarded to `authClient.listAccounts`.
|
|
15
|
+
*/
|
|
16
|
+
export function listAccountsOptions(
|
|
17
|
+
authClient: AuthClient,
|
|
18
|
+
userId?: string,
|
|
19
|
+
params?: Parameters<AuthClient["listAccounts"]>[0]
|
|
20
|
+
) {
|
|
21
|
+
return authQueryOptions(
|
|
22
|
+
authClient.listAccounts,
|
|
23
|
+
["auth", "user", userId, "listAccounts"],
|
|
24
|
+
params
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current user's device sessions
|
|
6
|
+
* (multi-session account switcher).
|
|
7
|
+
*
|
|
8
|
+
* Keyed per-user (enables offline account switching with a persister).
|
|
9
|
+
*
|
|
10
|
+
* @param authClient - The Better Auth client.
|
|
11
|
+
* @param userId - The current signed in user's ID.
|
|
12
|
+
* @param params - Parameters forwarded to `authClient.multiSession.listDeviceSessions`.
|
|
13
|
+
*/
|
|
14
|
+
export function listDeviceSessionsOptions(
|
|
15
|
+
authClient: AuthClient,
|
|
16
|
+
userId?: string,
|
|
17
|
+
params?: Parameters<AuthClient["multiSession"]["listDeviceSessions"]>[0]
|
|
18
|
+
) {
|
|
19
|
+
return authQueryOptions(
|
|
20
|
+
authClient.multiSession.listDeviceSessions,
|
|
21
|
+
["auth", "user", userId, "listDeviceSessions"],
|
|
22
|
+
params
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current user's active sessions.
|
|
6
|
+
*
|
|
7
|
+
* Keyed per-user (enables offline account switching with a persister).
|
|
8
|
+
*
|
|
9
|
+
* @param authClient - The Better Auth client.
|
|
10
|
+
* @param userId - The current signed in user's ID.
|
|
11
|
+
* @param params - Parameters forwarded to `authClient.listSessions`.
|
|
12
|
+
*/
|
|
13
|
+
export function listSessionsOptions(
|
|
14
|
+
authClient: AuthClient,
|
|
15
|
+
userId?: string,
|
|
16
|
+
params?: Parameters<AuthClient["listSessions"]>[0]
|
|
17
|
+
) {
|
|
18
|
+
return authQueryOptions(
|
|
19
|
+
authClient.listSessions,
|
|
20
|
+
["auth", "user", userId, "listSessions"],
|
|
21
|
+
params
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
2
|
+
import { authQueryOptions } from "../auth-query-options"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query options factory for the current user's passkeys.
|
|
6
|
+
*
|
|
7
|
+
* Keyed per-user (enables offline account switching with a persister).
|
|
8
|
+
*
|
|
9
|
+
* @param authClient - The Better Auth client.
|
|
10
|
+
* @param userId - The current signed in user's ID.
|
|
11
|
+
* @param params - Parameters forwarded to `authClient.passkey.listUserPasskeys`.
|
|
12
|
+
*/
|
|
13
|
+
export function listUserPasskeysOptions(
|
|
14
|
+
authClient: AuthClient,
|
|
15
|
+
userId?: string,
|
|
16
|
+
params?: Parameters<AuthClient["passkey"]["listUserPasskeys"]>[0]
|
|
17
|
+
) {
|
|
18
|
+
return authQueryOptions(
|
|
19
|
+
authClient.passkey.listUserPasskeys,
|
|
20
|
+
["auth", "user", userId, "listUserPasskeys"],
|
|
21
|
+
params
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type UseMutationOptions, type UseMutationResult } from "@tanstack/react-query";
|
|
2
|
-
import type { BetterFetchError } from "better-auth/react";
|
|
3
|
-
type AuthFn = (...args: any) => Promise<any>;
|
|
4
|
-
type MutationParams<TFn extends AuthFn> = undefined extends Parameters<TFn>[0] ? // biome-ignore lint/suspicious/noConfusingVoidType: void is needed for mutations with optional params
|
|
5
|
-
void | Omit<NonNullable<Parameters<TFn>[0]>, "fetchOptions"> : Omit<Parameters<TFn>[0], "fetchOptions">;
|
|
6
|
-
type InferMutationData<TFn extends AuthFn> = TFn extends (...args: infer _A) => infer R ? Extract<Awaited<R>, {
|
|
7
|
-
error: null;
|
|
8
|
-
}> extends {
|
|
9
|
-
data: infer D;
|
|
10
|
-
} ? D : Awaited<R> : Awaited<ReturnType<TFn>>;
|
|
11
|
-
export type UseAuthMutationOptions<TFn extends AuthFn> = Omit<UseMutationOptions<InferMutationData<TFn>, BetterFetchError, MutationParams<TFn>>, "mutationFn">;
|
|
12
|
-
export type UseAuthMutationResult<TFn extends AuthFn> = UseMutationResult<InferMutationData<TFn>, BetterFetchError, MutationParams<TFn>>;
|
|
13
|
-
type UseAuthMutationProps<TFn extends AuthFn> = {
|
|
14
|
-
authFn: TFn;
|
|
15
|
-
options?: UseAuthMutationOptions<TFn>;
|
|
16
|
-
};
|
|
17
|
-
export declare function useAuthMutation<TFn extends AuthFn>({ authFn, options }: UseAuthMutationProps<TFn>): UseAuthMutationResult<TFn>;
|
|
18
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
-
import type { BetterFetchError, BetterFetchOption } from "better-auth/react";
|
|
3
|
-
type BetterFetchFn = (options: {
|
|
4
|
-
fetchOptions?: BetterFetchOption;
|
|
5
|
-
}) => Promise<{
|
|
6
|
-
data: unknown;
|
|
7
|
-
}>;
|
|
8
|
-
type InferData<TFn> = TFn extends (options: {
|
|
9
|
-
fetchOptions?: BetterFetchOption;
|
|
10
|
-
}) => Promise<{
|
|
11
|
-
data: infer TData;
|
|
12
|
-
}> ? TData : never;
|
|
13
|
-
type OmitFetchOptions<T> = {
|
|
14
|
-
[K in keyof T as K extends "fetchOptions" ? never : K]: T[K];
|
|
15
|
-
};
|
|
16
|
-
export type UseAuthQueryOptions<TFn extends BetterFetchFn> = Omit<UseQueryOptions<InferData<TFn>, BetterFetchError>, "queryFn">;
|
|
17
|
-
export type UseAuthQueryResult<TFn extends BetterFetchFn> = UseQueryResult<InferData<TFn>, BetterFetchError>;
|
|
18
|
-
type UseAuthQueryProps<TFn extends BetterFetchFn> = {
|
|
19
|
-
authFn: TFn;
|
|
20
|
-
params?: OmitFetchOptions<Parameters<TFn>[0]>;
|
|
21
|
-
options: UseAuthQueryOptions<TFn>;
|
|
22
|
-
};
|
|
23
|
-
export declare function useAuthQuery<TFn extends BetterFetchFn>({ authFn, params, options }: UseAuthQueryProps<TFn>): UseQueryResult<import("@tanstack/react-query").NoInfer<InferData<TFn>>, BetterFetchError>;
|
|
24
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
export function useAuthQuery({ authFn, params, options }) {
|
|
3
|
-
return useQuery({
|
|
4
|
-
queryFn: async () => {
|
|
5
|
-
const result = await authFn({ ...params, fetchOptions: { throw: true } });
|
|
6
|
-
return result;
|
|
7
|
-
},
|
|
8
|
-
...options
|
|
9
|
-
});
|
|
10
|
-
}
|
package/dist/lib/auth-config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type UseMutationOptions,
|
|
3
|
-
type UseMutationResult,
|
|
4
|
-
useMutation
|
|
5
|
-
} from "@tanstack/react-query"
|
|
6
|
-
import type { BetterFetchError } from "better-auth/react"
|
|
7
|
-
|
|
8
|
-
// biome-ignore lint/suspicious/noExplicitAny: any
|
|
9
|
-
type AuthFn = (...args: any) => Promise<any>
|
|
10
|
-
|
|
11
|
-
type MutationParams<TFn extends AuthFn> = undefined extends Parameters<TFn>[0]
|
|
12
|
-
? // biome-ignore lint/suspicious/noConfusingVoidType: void is needed for mutations with optional params
|
|
13
|
-
void | Omit<NonNullable<Parameters<TFn>[0]>, "fetchOptions">
|
|
14
|
-
: Omit<Parameters<TFn>[0], "fetchOptions">
|
|
15
|
-
|
|
16
|
-
type InferMutationData<TFn extends AuthFn> = TFn extends (
|
|
17
|
-
...args: infer _A
|
|
18
|
-
) => infer R
|
|
19
|
-
? Extract<Awaited<R>, { error: null }> extends { data: infer D }
|
|
20
|
-
? D
|
|
21
|
-
: Awaited<R>
|
|
22
|
-
: Awaited<ReturnType<TFn>>
|
|
23
|
-
|
|
24
|
-
export type UseAuthMutationOptions<TFn extends AuthFn> = Omit<
|
|
25
|
-
UseMutationOptions<
|
|
26
|
-
InferMutationData<TFn>,
|
|
27
|
-
BetterFetchError,
|
|
28
|
-
MutationParams<TFn>
|
|
29
|
-
>,
|
|
30
|
-
"mutationFn"
|
|
31
|
-
>
|
|
32
|
-
|
|
33
|
-
export type UseAuthMutationResult<TFn extends AuthFn> = UseMutationResult<
|
|
34
|
-
InferMutationData<TFn>,
|
|
35
|
-
BetterFetchError,
|
|
36
|
-
MutationParams<TFn>
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
type UseAuthMutationProps<TFn extends AuthFn> = {
|
|
40
|
-
authFn: TFn
|
|
41
|
-
options?: UseAuthMutationOptions<TFn>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function useAuthMutation<TFn extends AuthFn>({
|
|
45
|
-
authFn,
|
|
46
|
-
options
|
|
47
|
-
}: UseAuthMutationProps<TFn>): UseAuthMutationResult<TFn> {
|
|
48
|
-
return useMutation({
|
|
49
|
-
mutationFn: (params) =>
|
|
50
|
-
authFn({
|
|
51
|
-
...params,
|
|
52
|
-
fetchOptions: { throw: true }
|
|
53
|
-
}),
|
|
54
|
-
...options
|
|
55
|
-
})
|
|
56
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type UseQueryOptions,
|
|
3
|
-
type UseQueryResult,
|
|
4
|
-
useQuery
|
|
5
|
-
} from "@tanstack/react-query"
|
|
6
|
-
import type { BetterFetchError, BetterFetchOption } from "better-auth/react"
|
|
7
|
-
|
|
8
|
-
type BetterFetchFn = (options: {
|
|
9
|
-
fetchOptions?: BetterFetchOption
|
|
10
|
-
}) => Promise<{ data: unknown }>
|
|
11
|
-
|
|
12
|
-
type InferData<TFn> = TFn extends (options: {
|
|
13
|
-
fetchOptions?: BetterFetchOption
|
|
14
|
-
}) => Promise<{ data: infer TData }>
|
|
15
|
-
? TData
|
|
16
|
-
: never
|
|
17
|
-
|
|
18
|
-
type OmitFetchOptions<T> = {
|
|
19
|
-
[K in keyof T as K extends "fetchOptions" ? never : K]: T[K]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type UseAuthQueryOptions<TFn extends BetterFetchFn> = Omit<
|
|
23
|
-
UseQueryOptions<InferData<TFn>, BetterFetchError>,
|
|
24
|
-
"queryFn"
|
|
25
|
-
>
|
|
26
|
-
|
|
27
|
-
export type UseAuthQueryResult<TFn extends BetterFetchFn> = UseQueryResult<
|
|
28
|
-
InferData<TFn>,
|
|
29
|
-
BetterFetchError
|
|
30
|
-
>
|
|
31
|
-
|
|
32
|
-
type UseAuthQueryProps<TFn extends BetterFetchFn> = {
|
|
33
|
-
authFn: TFn
|
|
34
|
-
params?: OmitFetchOptions<Parameters<TFn>[0]>
|
|
35
|
-
options: UseAuthQueryOptions<TFn>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function useAuthQuery<TFn extends BetterFetchFn>({
|
|
39
|
-
authFn,
|
|
40
|
-
params,
|
|
41
|
-
options
|
|
42
|
-
}: UseAuthQueryProps<TFn>) {
|
|
43
|
-
return useQuery<InferData<TFn>, BetterFetchError>({
|
|
44
|
-
queryFn: async () => {
|
|
45
|
-
const result = await authFn({ ...params, fetchOptions: { throw: true } })
|
|
46
|
-
return result as InferData<TFn>
|
|
47
|
-
},
|
|
48
|
-
...options
|
|
49
|
-
})
|
|
50
|
-
}
|