@better-auth-ui/react 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/auth/auth-provider.d.ts +32 -0
- package/dist/components/auth/auth-provider.js +44 -0
- package/dist/components/email/email-changed.d.ts +97 -0
- package/dist/components/email/email-changed.js +70 -0
- package/dist/components/email/email-localization.d.ts +61 -0
- package/dist/components/email/email-localization.js +24 -0
- package/dist/components/email/email-styles.d.ts +89 -0
- package/dist/components/email/email-styles.js +129 -0
- package/dist/components/email/email-verification.d.ts +97 -0
- package/dist/components/email/email-verification.js +75 -0
- package/dist/components/email/index.d.ts +9 -0
- package/dist/components/email/index.js +9 -0
- package/dist/components/email/magic-link.d.ts +93 -0
- package/dist/components/email/magic-link.js +72 -0
- package/dist/components/email/new-device.d.ts +123 -0
- package/dist/components/email/new-device.js +90 -0
- package/dist/components/email/otp-email.d.ts +88 -0
- package/dist/components/email/otp-email.js +65 -0
- package/dist/components/email/password-changed.d.ts +96 -0
- package/dist/components/email/password-changed.js +76 -0
- package/dist/components/email/reset-password.d.ts +90 -0
- package/dist/components/email/reset-password.js +68 -0
- package/dist/components/icons/apple.d.ts +8 -0
- package/dist/components/icons/apple.js +10 -0
- package/dist/components/icons/atlassian.d.ts +10 -0
- package/dist/components/icons/atlassian.js +14 -0
- package/dist/components/icons/cognito.d.ts +8 -0
- package/dist/components/icons/cognito.js +10 -0
- package/dist/components/icons/discord.d.ts +8 -0
- package/dist/components/icons/discord.js +10 -0
- package/dist/components/icons/dropbox.d.ts +8 -0
- package/dist/components/icons/dropbox.js +10 -0
- package/dist/components/icons/facebook.d.ts +10 -0
- package/dist/components/icons/facebook.js +12 -0
- package/dist/components/icons/figma.d.ts +11 -0
- package/dist/components/icons/figma.js +13 -0
- package/dist/components/icons/github.d.ts +10 -0
- package/dist/components/icons/github.js +12 -0
- package/dist/components/icons/gitlab.d.ts +8 -0
- package/dist/components/icons/gitlab.js +10 -0
- package/dist/components/icons/google.d.ts +8 -0
- package/dist/components/icons/google.js +10 -0
- package/dist/components/icons/huggingface.d.ts +8 -0
- package/dist/components/icons/huggingface.js +10 -0
- package/dist/components/icons/index.d.ts +35 -0
- package/dist/components/icons/index.js +35 -0
- package/dist/components/icons/kakao.d.ts +10 -0
- package/dist/components/icons/kakao.js +12 -0
- package/dist/components/icons/kick.d.ts +10 -0
- package/dist/components/icons/kick.js +12 -0
- package/dist/components/icons/line.d.ts +8 -0
- package/dist/components/icons/line.js +10 -0
- package/dist/components/icons/linear.d.ts +8 -0
- package/dist/components/icons/linear.js +10 -0
- package/dist/components/icons/linkedin.d.ts +8 -0
- package/dist/components/icons/linkedin.js +10 -0
- package/dist/components/icons/microsoft.d.ts +8 -0
- package/dist/components/icons/microsoft.js +10 -0
- package/dist/components/icons/naver.d.ts +8 -0
- package/dist/components/icons/naver.js +10 -0
- package/dist/components/icons/notion.d.ts +8 -0
- package/dist/components/icons/notion.js +10 -0
- package/dist/components/icons/paybin.d.ts +7 -0
- package/dist/components/icons/paybin.js +9 -0
- package/dist/components/icons/paypal.d.ts +8 -0
- package/dist/components/icons/paypal.js +10 -0
- package/dist/components/icons/polar.d.ts +8 -0
- package/dist/components/icons/polar.js +10 -0
- package/dist/components/icons/railway.d.ts +8 -0
- package/dist/components/icons/railway.js +10 -0
- package/dist/components/icons/reddit.d.ts +8 -0
- package/dist/components/icons/reddit.js +10 -0
- package/dist/components/icons/roblox.d.ts +11 -0
- package/dist/components/icons/roblox.js +13 -0
- package/dist/components/icons/salesforce.d.ts +8 -0
- package/dist/components/icons/salesforce.js +10 -0
- package/dist/components/icons/slack.d.ts +8 -0
- package/dist/components/icons/slack.js +10 -0
- package/dist/components/icons/spotify.d.ts +8 -0
- package/dist/components/icons/spotify.js +10 -0
- package/dist/components/icons/tiktok.d.ts +9 -0
- package/dist/components/icons/tiktok.js +11 -0
- package/dist/components/icons/twitch.d.ts +8 -0
- package/dist/components/icons/twitch.js +13 -0
- package/dist/components/icons/vercel.d.ts +8 -0
- package/dist/components/icons/vercel.js +10 -0
- package/dist/components/icons/vk.d.ts +8 -0
- package/dist/components/icons/vk.js +10 -0
- package/dist/components/icons/wechat.d.ts +8 -0
- package/dist/components/icons/wechat.js +10 -0
- package/dist/components/icons/x.d.ts +8 -0
- package/dist/components/icons/x.js +10 -0
- package/dist/components/icons/zoom.d.ts +8 -0
- package/dist/components/icons/zoom.js +12 -0
- package/dist/components/settings/account/theme-preview.d.ts +3 -0
- package/dist/components/settings/account/theme-preview.js +10 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/hooks/auth/use-auth-mutation.d.ts +18 -0
- package/dist/hooks/auth/use-auth-mutation.js +10 -0
- package/dist/hooks/auth/use-auth-query.d.ts +24 -0
- package/dist/hooks/auth/use-auth-query.js +10 -0
- package/dist/hooks/auth/use-authenticate.d.ts +9 -0
- package/dist/hooks/auth/use-authenticate.js +28 -0
- package/dist/hooks/auth/use-forgot-password.d.ts +20 -0
- package/dist/hooks/auth/use-forgot-password.js +14 -0
- package/dist/hooks/auth/use-request-password-reset.d.ts +26 -0
- package/dist/hooks/auth/use-request-password-reset.js +14 -0
- package/dist/hooks/auth/use-reset-password.d.ts +40 -0
- package/dist/hooks/auth/use-reset-password.js +13 -0
- package/dist/hooks/auth/use-send-verification-email.d.ts +24 -0
- package/dist/hooks/auth/use-send-verification-email.js +13 -0
- package/dist/hooks/auth/use-session.d.ts +9 -0
- package/dist/hooks/auth/use-session.js +18 -0
- package/dist/hooks/auth/use-sign-in-email.d.ts +53 -0
- package/dist/hooks/auth/use-sign-in-email.js +24 -0
- package/dist/hooks/auth/use-sign-in-magic-link.d.ts +32 -0
- package/dist/hooks/auth/use-sign-in-magic-link.js +13 -0
- package/dist/hooks/auth/use-sign-in-social.d.ts +93 -0
- package/dist/hooks/auth/use-sign-in-social.js +13 -0
- package/dist/hooks/auth/use-sign-out.d.ts +19 -0
- package/dist/hooks/auth/use-sign-out.js +24 -0
- package/dist/hooks/auth/use-sign-up-email.d.ts +526 -0
- package/dist/hooks/auth/use-sign-up-email.js +24 -0
- package/dist/hooks/auth/use-user.d.ts +513 -0
- package/dist/hooks/auth/use-user.js +14 -0
- package/dist/hooks/settings/use-account-info.d.ts +17 -0
- package/dist/hooks/settings/use-account-info.js +25 -0
- package/dist/hooks/settings/use-change-email.d.ts +24 -0
- package/dist/hooks/settings/use-change-email.js +23 -0
- package/dist/hooks/settings/use-change-password.d.ts +54 -0
- package/dist/hooks/settings/use-change-password.js +11 -0
- package/dist/hooks/settings/use-delete-user.d.ts +42 -0
- package/dist/hooks/settings/use-delete-user.js +11 -0
- package/dist/hooks/settings/use-link-social.d.ts +46 -0
- package/dist/hooks/settings/use-link-social.js +10 -0
- package/dist/hooks/settings/use-list-accounts.d.ts +20 -0
- package/dist/hooks/settings/use-list-accounts.js +23 -0
- package/dist/hooks/settings/use-list-device-sessions.d.ts +11 -0
- package/dist/hooks/settings/use-list-device-sessions.js +22 -0
- package/dist/hooks/settings/use-list-sessions.d.ts +20 -0
- package/dist/hooks/settings/use-list-sessions.js +22 -0
- package/dist/hooks/settings/use-revoke-multi-session.d.ts +19 -0
- package/dist/hooks/settings/use-revoke-multi-session.js +20 -0
- package/dist/hooks/settings/use-revoke-session.d.ts +19 -0
- package/dist/hooks/settings/use-revoke-session.js +21 -0
- package/dist/hooks/settings/use-set-active-session.d.ts +37 -0
- package/dist/hooks/settings/use-set-active-session.js +28 -0
- package/dist/hooks/settings/use-unlink-account.d.ts +21 -0
- package/dist/hooks/settings/use-unlink-account.js +21 -0
- package/dist/hooks/settings/use-update-user.d.ts +11 -0
- package/dist/hooks/settings/use-update-user.js +29 -0
- package/dist/hooks/use-hydrated.d.ts +6 -0
- package/dist/hooks/use-hydrated.js +18 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +33 -0
- package/dist/lib/auth-client.d.ts +1979 -0
- package/dist/lib/auth-client.js +5 -0
- package/dist/lib/auth-config.d.ts +43 -0
- package/dist/lib/auth-config.js +1 -0
- package/dist/lib/auth-context.d.ts +2 -0
- package/dist/lib/auth-context.js +3 -0
- package/dist/lib/auth-hook-options.d.ts +8 -0
- package/dist/lib/auth-hook-options.js +1 -0
- package/dist/lib/provider-icons.d.ts +13 -0
- package/dist/lib/provider-icons.js +48 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/package.json +64 -0
- package/src/components/auth/auth-provider.tsx +82 -0
- package/src/components/email/email-changed.tsx +381 -0
- package/src/components/email/email-localization.tsx +33 -0
- package/src/components/email/email-styles.tsx +175 -0
- package/src/components/email/email-verification.tsx +350 -0
- package/src/components/email/index.ts +9 -0
- package/src/components/email/magic-link.tsx +349 -0
- package/src/components/email/new-device.tsx +452 -0
- package/src/components/email/otp-email.tsx +321 -0
- package/src/components/email/password-changed.tsx +380 -0
- package/src/components/email/reset-password.tsx +343 -0
- package/src/components/icons/apple.tsx +24 -0
- package/src/components/icons/atlassian.tsx +43 -0
- package/src/components/icons/cognito.tsx +25 -0
- package/src/components/icons/discord.tsx +24 -0
- package/src/components/icons/dropbox.tsx +24 -0
- package/src/components/icons/facebook.tsx +30 -0
- package/src/components/icons/figma.tsx +43 -0
- package/src/components/icons/github.tsx +26 -0
- package/src/components/icons/gitlab.tsx +36 -0
- package/src/components/icons/google.tsx +42 -0
- package/src/components/icons/huggingface.tsx +44 -0
- package/src/components/icons/index.ts +35 -0
- package/src/components/icons/kakao.tsx +26 -0
- package/src/components/icons/kick.tsx +30 -0
- package/src/components/icons/line.tsx +24 -0
- package/src/components/icons/linear.tsx +24 -0
- package/src/components/icons/linkedin.tsx +28 -0
- package/src/components/icons/microsoft.tsx +24 -0
- package/src/components/icons/naver.tsx +24 -0
- package/src/components/icons/notion.tsx +25 -0
- package/src/components/icons/paybin.tsx +37 -0
- package/src/components/icons/paypal.tsx +36 -0
- package/src/components/icons/polar.tsx +31 -0
- package/src/components/icons/railway.tsx +24 -0
- package/src/components/icons/reddit.tsx +25 -0
- package/src/components/icons/roblox.tsx +28 -0
- package/src/components/icons/salesforce.tsx +24 -0
- package/src/components/icons/slack.tsx +36 -0
- package/src/components/icons/spotify.tsx +24 -0
- package/src/components/icons/tiktok.tsx +32 -0
- package/src/components/icons/twitch.tsx +50 -0
- package/src/components/icons/vercel.tsx +21 -0
- package/src/components/icons/vk.tsx +24 -0
- package/src/components/icons/wechat.tsx +24 -0
- package/src/components/icons/x.tsx +24 -0
- package/src/components/icons/zoom.tsx +48 -0
- package/src/components/settings/account/theme-preview.tsx +271 -0
- package/src/core.ts +1 -0
- package/src/hooks/auth/use-auth-mutation.ts +56 -0
- package/src/hooks/auth/use-auth-query.ts +50 -0
- package/src/hooks/auth/use-authenticate.ts +35 -0
- package/src/hooks/auth/use-request-password-reset.ts +24 -0
- package/src/hooks/auth/use-reset-password.ts +23 -0
- package/src/hooks/auth/use-send-verification-email.ts +23 -0
- package/src/hooks/auth/use-session.ts +26 -0
- package/src/hooks/auth/use-sign-in-email.ts +35 -0
- package/src/hooks/auth/use-sign-in-magic-link.ts +23 -0
- package/src/hooks/auth/use-sign-in-social.ts +23 -0
- package/src/hooks/auth/use-sign-out.ts +34 -0
- package/src/hooks/auth/use-sign-up-email.ts +35 -0
- package/src/hooks/auth/use-user.ts +21 -0
- package/src/hooks/settings/use-account-info.ts +30 -0
- package/src/hooks/settings/use-change-email.ts +33 -0
- package/src/hooks/settings/use-change-password.ts +21 -0
- package/src/hooks/settings/use-delete-user.ts +21 -0
- package/src/hooks/settings/use-link-social.ts +19 -0
- package/src/hooks/settings/use-list-accounts.ts +27 -0
- package/src/hooks/settings/use-list-device-sessions.ts +32 -0
- package/src/hooks/settings/use-list-sessions.ts +26 -0
- package/src/hooks/settings/use-revoke-multi-session.ts +30 -0
- package/src/hooks/settings/use-revoke-session.ts +31 -0
- package/src/hooks/settings/use-set-active-session.ts +46 -0
- package/src/hooks/settings/use-unlink-account.ts +31 -0
- package/src/hooks/settings/use-update-user.ts +44 -0
- package/src/index.ts +34 -0
- package/src/lib/auth-client.ts +37 -0
- package/src/lib/auth-config.ts +48 -0
- package/src/lib/auth-context.ts +6 -0
- package/src/lib/provider-icons.ts +90 -0
- package/src/lib/utils.ts +6 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for the reset-password flow.
|
|
12
|
+
*
|
|
13
|
+
* The mutation resets the user's password using the provided token and new password.
|
|
14
|
+
*
|
|
15
|
+
* @returns The `useMutation` result.
|
|
16
|
+
*/
|
|
17
|
+
export function useResetPassword(
|
|
18
|
+
options?: UseAuthMutationOptions<AuthClient["resetPassword"]>
|
|
19
|
+
) {
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({ authFn: authClient.resetPassword, options })
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation to send a verification email.
|
|
12
|
+
*
|
|
13
|
+
* The mutation sends a verification email to the specified email address.
|
|
14
|
+
*
|
|
15
|
+
* @returns The `useMutation` result.
|
|
16
|
+
*/
|
|
17
|
+
export function useSendVerificationEmail(
|
|
18
|
+
options?: UseAuthMutationOptions<AuthClient["sendVerificationEmail"]>
|
|
19
|
+
) {
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({ authFn: authClient.sendVerificationEmail, options })
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type AuthClient, useAuth } from "@better-auth-ui/react"
|
|
2
|
+
import {
|
|
3
|
+
type UseAuthQueryOptions,
|
|
4
|
+
type UseAuthQueryResult,
|
|
5
|
+
useAuthQuery
|
|
6
|
+
} from "./use-auth-query"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve the current authentication session.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Options to merge into the React Query configuration for the session query.
|
|
12
|
+
* @returns The React Query result for the session query: `data` contains session information, `isLoading`/`isFetching` indicate loading state, and `error` contains any fetch error.
|
|
13
|
+
*/
|
|
14
|
+
export function useSession(
|
|
15
|
+
options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
|
|
16
|
+
): UseAuthQueryResult<AuthClient["getSession"]> {
|
|
17
|
+
const { authClient } = useAuth()
|
|
18
|
+
|
|
19
|
+
return useAuthQuery({
|
|
20
|
+
authFn: authClient.getSession,
|
|
21
|
+
options: {
|
|
22
|
+
queryKey: ["auth", "getSession"],
|
|
23
|
+
...options
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useSession
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
8
|
+
|
|
9
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook that creates a mutation for email/password sign-in.
|
|
13
|
+
*
|
|
14
|
+
* The mutation sends an email/password sign-in request and
|
|
15
|
+
* refetches the session on completion.
|
|
16
|
+
*
|
|
17
|
+
* @returns The `useMutation` result.
|
|
18
|
+
*/
|
|
19
|
+
export function useSignInEmail(
|
|
20
|
+
options?: UseAuthMutationOptions<AuthClient["signIn"]["email"]>
|
|
21
|
+
) {
|
|
22
|
+
const { authClient } = useAuth()
|
|
23
|
+
const { refetch } = useSession({ refetchOnMount: false })
|
|
24
|
+
|
|
25
|
+
return useAuthMutation({
|
|
26
|
+
authFn: authClient.signIn.email,
|
|
27
|
+
options: {
|
|
28
|
+
...options,
|
|
29
|
+
onSuccess: async (...args) => {
|
|
30
|
+
await refetch()
|
|
31
|
+
await options?.onSuccess?.(...args)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for magic-link sign-in.
|
|
12
|
+
*
|
|
13
|
+
* The mutation sends a magic-link sign-in email to the specified address.
|
|
14
|
+
*
|
|
15
|
+
* @returns The `useMutation` result.
|
|
16
|
+
*/
|
|
17
|
+
export function useSignInMagicLink(
|
|
18
|
+
options?: UseAuthMutationOptions<AuthClient["signIn"]["magicLink"]>
|
|
19
|
+
) {
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({ authFn: authClient.signIn.magicLink, options })
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for social sign-in.
|
|
12
|
+
*
|
|
13
|
+
* The mutation initiates a social sign-in flow with the specified provider.
|
|
14
|
+
*
|
|
15
|
+
* @returns The `useMutation` result.
|
|
16
|
+
*/
|
|
17
|
+
export function useSignInSocial(
|
|
18
|
+
options?: UseAuthMutationOptions<AuthClient["signIn"]["social"]>
|
|
19
|
+
) {
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
|
|
22
|
+
return useAuthMutation({ authFn: authClient.signIn.social, options })
|
|
23
|
+
}
|
|
@@ -0,0 +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"
|
|
8
|
+
|
|
9
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook that creates a mutation for signing out.
|
|
13
|
+
*
|
|
14
|
+
* The mutation signs out the current user and removes auth queries from cache.
|
|
15
|
+
*
|
|
16
|
+
* @returns The `useMutation` result.
|
|
17
|
+
*/
|
|
18
|
+
export function useSignOut(
|
|
19
|
+
options?: UseAuthMutationOptions<AuthClient["signOut"]>
|
|
20
|
+
) {
|
|
21
|
+
const { authClient } = useAuth()
|
|
22
|
+
const queryClient = useQueryClient()
|
|
23
|
+
|
|
24
|
+
return useAuthMutation({
|
|
25
|
+
authFn: authClient.signOut,
|
|
26
|
+
options: {
|
|
27
|
+
...options,
|
|
28
|
+
onSuccess: async (...args) => {
|
|
29
|
+
queryClient.removeQueries({ queryKey: ["auth"] })
|
|
30
|
+
await options?.onSuccess?.(...args)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useSession
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import type { UseAuthMutationOptions } from "./use-auth-mutation"
|
|
8
|
+
|
|
9
|
+
export { useAuthMutation } from "./use-auth-mutation"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook that creates a mutation for email/password sign-up.
|
|
13
|
+
*
|
|
14
|
+
* The mutation sends an email/password sign-up request and
|
|
15
|
+
* refetches the session on success.
|
|
16
|
+
*
|
|
17
|
+
* @returns The `useMutation` result.
|
|
18
|
+
*/
|
|
19
|
+
export function useSignUpEmail(
|
|
20
|
+
options?: UseAuthMutationOptions<AuthClient["signUp"]["email"]>
|
|
21
|
+
) {
|
|
22
|
+
const { authClient } = useAuth()
|
|
23
|
+
const { refetch } = useSession({ refetchOnMount: false })
|
|
24
|
+
|
|
25
|
+
return useAuthMutation({
|
|
26
|
+
authFn: authClient.signUp.email,
|
|
27
|
+
options: {
|
|
28
|
+
...options,
|
|
29
|
+
onSuccess: async (...args) => {
|
|
30
|
+
await refetch()
|
|
31
|
+
await options?.onSuccess?.(...args)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AuthClient } from "@better-auth-ui/react"
|
|
2
|
+
import type { UseAuthQueryOptions } from "./use-auth-query"
|
|
3
|
+
|
|
4
|
+
import { useSession } from "./use-session"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieve the current authenticated user.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Options to merge into the React Query configuration for the session query.
|
|
10
|
+
* @returns The React Query result with `data` containing the user object from the session.
|
|
11
|
+
*/
|
|
12
|
+
export function useUser(
|
|
13
|
+
options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
|
|
14
|
+
) {
|
|
15
|
+
const { data, ...rest } = useSession(options)
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
data: data?.user,
|
|
19
|
+
...rest
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AuthClient, useAuth } from "@better-auth-ui/react"
|
|
2
|
+
import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve provider-specific account info for a given account ID.
|
|
6
|
+
*
|
|
7
|
+
* Uses the `accountInfo` API endpoint to fetch detailed information
|
|
8
|
+
* from the social provider. The provider is automatically detected
|
|
9
|
+
* from the account ID.
|
|
10
|
+
*
|
|
11
|
+
* @param accountId - The provider-given account ID to fetch info for
|
|
12
|
+
* @param options - Optional react-query options forwarded to `useQuery`
|
|
13
|
+
* @returns The react-query result containing account info data, loading state, and error state
|
|
14
|
+
*/
|
|
15
|
+
export function useAccountInfo(
|
|
16
|
+
accountId?: string,
|
|
17
|
+
options?: Partial<UseAuthQueryOptions<AuthClient["accountInfo"]>>
|
|
18
|
+
) {
|
|
19
|
+
const { authClient } = useAuth()
|
|
20
|
+
|
|
21
|
+
return useAuthQuery({
|
|
22
|
+
authFn: authClient.accountInfo,
|
|
23
|
+
params: { query: { accountId } },
|
|
24
|
+
options: {
|
|
25
|
+
queryKey: ["auth", "accountInfo", accountId],
|
|
26
|
+
enabled: !!accountId,
|
|
27
|
+
...options
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useSession
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook that creates a mutation for changing the current user's email address.
|
|
11
|
+
*
|
|
12
|
+
* The mutation sends an email-change request and shows success or error toasts.
|
|
13
|
+
* On success the callback URL is set to the account settings view.
|
|
14
|
+
*
|
|
15
|
+
* @returns The `useMutation` result.
|
|
16
|
+
*/
|
|
17
|
+
export function useChangeEmail(
|
|
18
|
+
options?: UseAuthMutationOptions<AuthClient["changeEmail"]>
|
|
19
|
+
) {
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
const { refetch } = useSession({ refetchOnMount: false })
|
|
22
|
+
|
|
23
|
+
return useAuthMutation({
|
|
24
|
+
authFn: authClient.changeEmail,
|
|
25
|
+
options: {
|
|
26
|
+
...options,
|
|
27
|
+
onSuccess: async (...args) => {
|
|
28
|
+
refetch()
|
|
29
|
+
await options?.onSuccess?.(...args)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "../auth/use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for changing the authenticated user's password.
|
|
12
|
+
*
|
|
13
|
+
* @returns The `useMutation` result.
|
|
14
|
+
*/
|
|
15
|
+
export function useChangePassword(
|
|
16
|
+
options?: UseAuthMutationOptions<AuthClient["changePassword"]>
|
|
17
|
+
) {
|
|
18
|
+
const { authClient } = useAuth()
|
|
19
|
+
|
|
20
|
+
return useAuthMutation({ authFn: authClient.changePassword, options })
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
export { useAuthMutation } from "../auth/use-auth-mutation"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for deleting the authenticated user account.
|
|
12
|
+
*
|
|
13
|
+
* @returns The `useMutation` result.
|
|
14
|
+
*/
|
|
15
|
+
export function useDeleteUser(
|
|
16
|
+
options?: UseAuthMutationOptions<AuthClient["deleteUser"]>
|
|
17
|
+
) {
|
|
18
|
+
const { authClient } = useAuth()
|
|
19
|
+
|
|
20
|
+
return useAuthMutation({ authFn: authClient.deleteUser, options })
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook that creates a mutation for linking a social provider to the current user.
|
|
10
|
+
*
|
|
11
|
+
* @returns The `useMutation` result.
|
|
12
|
+
*/
|
|
13
|
+
export function useLinkSocial(
|
|
14
|
+
options?: UseAuthMutationOptions<AuthClient["linkSocial"]>
|
|
15
|
+
) {
|
|
16
|
+
const { authClient } = useAuth()
|
|
17
|
+
|
|
18
|
+
return useAuthMutation({ authFn: authClient.linkSocial, options })
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AuthClient, useAuth, useSession } from "@better-auth-ui/react"
|
|
2
|
+
import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve the current user's linked social accounts.
|
|
6
|
+
*
|
|
7
|
+
* The query runs only when at least one social provider is configured and a session exists.
|
|
8
|
+
* The provided `options` are forwarded to both `useSession` and `useQuery`, allowing customization of initial data and query behavior.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Optional react-query / initial-data options forwarded to `useSession` and `useQuery`
|
|
11
|
+
* @returns The react-query result containing linked accounts data, loading state, and error state
|
|
12
|
+
*/
|
|
13
|
+
export function useListAccounts(
|
|
14
|
+
options?: Partial<UseAuthQueryOptions<AuthClient["listAccounts"]>>
|
|
15
|
+
) {
|
|
16
|
+
const { authClient } = useAuth()
|
|
17
|
+
const { data: session } = useSession({ refetchOnMount: false })
|
|
18
|
+
|
|
19
|
+
return useAuthQuery({
|
|
20
|
+
authFn: authClient.listAccounts,
|
|
21
|
+
options: {
|
|
22
|
+
queryKey: ["auth", "listAccounts", session?.user.id],
|
|
23
|
+
enabled: !!session,
|
|
24
|
+
...options
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AuthClient, useAuth, useSession } from "@better-auth-ui/react"
|
|
2
|
+
import {
|
|
3
|
+
type UseAuthQueryOptions,
|
|
4
|
+
type UseAuthQueryResult,
|
|
5
|
+
useAuthQuery
|
|
6
|
+
} from "../auth/use-auth-query"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve device sessions for multi-session account switching.
|
|
10
|
+
*
|
|
11
|
+
* The query is enabled only when `multiSession` is true and session data is available.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Optional React Query options to customize the query behavior.
|
|
14
|
+
* @returns The React Query result for the device sessions list; `data` is the array of device session objects and includes loading and error states.
|
|
15
|
+
*/
|
|
16
|
+
export function useListDeviceSessions(
|
|
17
|
+
options?: Partial<
|
|
18
|
+
UseAuthQueryOptions<AuthClient["multiSession"]["listDeviceSessions"]>
|
|
19
|
+
>
|
|
20
|
+
): UseAuthQueryResult<AuthClient["multiSession"]["listDeviceSessions"]> {
|
|
21
|
+
const { authClient } = useAuth()
|
|
22
|
+
const { data: session } = useSession({ refetchOnMount: false })
|
|
23
|
+
|
|
24
|
+
return useAuthQuery({
|
|
25
|
+
authFn: authClient.multiSession.listDeviceSessions,
|
|
26
|
+
options: {
|
|
27
|
+
queryKey: ["auth", "multiSession", "listDeviceSessions"],
|
|
28
|
+
enabled: !!session,
|
|
29
|
+
...options
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type AuthClient, useAuth, useSession } from "@better-auth-ui/react"
|
|
2
|
+
import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve the active sessions (devices where the current user is signed in).
|
|
6
|
+
*
|
|
7
|
+
* The underlying query is enabled only when session data is available.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Optional React Query options to customize the query behavior.
|
|
10
|
+
* @returns The React Query result for the sessions list; `data` is the array of session objects, and the result includes loading and error states.
|
|
11
|
+
*/
|
|
12
|
+
export function useListSessions(
|
|
13
|
+
options?: Partial<UseAuthQueryOptions<AuthClient["listSessions"]>>
|
|
14
|
+
) {
|
|
15
|
+
const { authClient } = useAuth()
|
|
16
|
+
const { data: session } = useSession({ refetchOnMount: false })
|
|
17
|
+
|
|
18
|
+
return useAuthQuery({
|
|
19
|
+
authFn: authClient.listSessions,
|
|
20
|
+
options: {
|
|
21
|
+
queryKey: ["auth", "listSessions", session?.user.id],
|
|
22
|
+
enabled: !!session,
|
|
23
|
+
...options
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useListDeviceSessions
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook that creates a mutation for revoking a device session in multi-session mode.
|
|
11
|
+
*
|
|
12
|
+
* @returns The `useMutation` result.
|
|
13
|
+
*/
|
|
14
|
+
export function useRevokeMultiSession(
|
|
15
|
+
options?: UseAuthMutationOptions<AuthClient["multiSession"]["revoke"]>
|
|
16
|
+
) {
|
|
17
|
+
const { authClient } = useAuth()
|
|
18
|
+
const { refetch } = useListDeviceSessions({ refetchOnMount: false })
|
|
19
|
+
|
|
20
|
+
return useAuthMutation({
|
|
21
|
+
authFn: authClient.multiSession.revoke,
|
|
22
|
+
options: {
|
|
23
|
+
...options,
|
|
24
|
+
onSuccess: async (...args) => {
|
|
25
|
+
await refetch()
|
|
26
|
+
await options?.onSuccess?.(...args)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
import { useListSessions } from "./use-list-sessions"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for revoking a user session.
|
|
12
|
+
*
|
|
13
|
+
* @returns The `useMutation` result.
|
|
14
|
+
*/
|
|
15
|
+
export function useRevokeSession(
|
|
16
|
+
options?: UseAuthMutationOptions<AuthClient["revokeSession"]>
|
|
17
|
+
) {
|
|
18
|
+
const { authClient } = useAuth()
|
|
19
|
+
const { refetch } = useListSessions({ refetchOnMount: false })
|
|
20
|
+
|
|
21
|
+
return useAuthMutation({
|
|
22
|
+
authFn: authClient.revokeSession,
|
|
23
|
+
options: {
|
|
24
|
+
...options,
|
|
25
|
+
onSuccess: async (...args) => {
|
|
26
|
+
await refetch()
|
|
27
|
+
await options?.onSuccess?.(...args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useListDeviceSessions,
|
|
6
|
+
useSession
|
|
7
|
+
} from "@better-auth-ui/react"
|
|
8
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
9
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook that sets an active device session in multi-session mode.
|
|
13
|
+
*
|
|
14
|
+
* @returns The `useMutation` result.
|
|
15
|
+
*/
|
|
16
|
+
export function useSetActiveSession(
|
|
17
|
+
options?: UseAuthMutationOptions<AuthClient["multiSession"]["setActive"]>
|
|
18
|
+
) {
|
|
19
|
+
const queryClient = useQueryClient()
|
|
20
|
+
const { authClient } = useAuth()
|
|
21
|
+
|
|
22
|
+
const { refetch: refetchSession } = useSession({ refetchOnMount: false })
|
|
23
|
+
const { data: deviceSessions, refetch: refetchDeviceSessions } =
|
|
24
|
+
useListDeviceSessions({ refetchOnMount: false })
|
|
25
|
+
|
|
26
|
+
return useAuthMutation({
|
|
27
|
+
authFn: authClient.multiSession.setActive,
|
|
28
|
+
options: {
|
|
29
|
+
...options,
|
|
30
|
+
onSuccess: async (data, { sessionToken }, ...args) => {
|
|
31
|
+
const deviceSession = deviceSessions?.find(
|
|
32
|
+
(session) => session.session.token === sessionToken
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
if (deviceSession)
|
|
36
|
+
queryClient.setQueryData(["auth", "getSession"], deviceSession)
|
|
37
|
+
|
|
38
|
+
window.scrollTo({ top: 0 })
|
|
39
|
+
|
|
40
|
+
await refetchSession()
|
|
41
|
+
await refetchDeviceSessions()
|
|
42
|
+
await options?.onSuccess?.(data, { sessionToken }, ...args)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation
|
|
5
|
+
} from "@better-auth-ui/react"
|
|
6
|
+
import type { UseAuthMutationOptions } from "../auth/use-auth-mutation"
|
|
7
|
+
|
|
8
|
+
import { useListAccounts } from "./use-list-accounts"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates a mutation for unlinking a social provider from the current user.
|
|
12
|
+
*
|
|
13
|
+
* @returns The `useMutation` result.
|
|
14
|
+
*/
|
|
15
|
+
export function useUnlinkAccount(
|
|
16
|
+
options?: UseAuthMutationOptions<AuthClient["unlinkAccount"]>
|
|
17
|
+
) {
|
|
18
|
+
const { authClient } = useAuth()
|
|
19
|
+
const { refetch } = useListAccounts({ refetchOnMount: false })
|
|
20
|
+
|
|
21
|
+
return useAuthMutation({
|
|
22
|
+
authFn: authClient.unlinkAccount,
|
|
23
|
+
options: {
|
|
24
|
+
...options,
|
|
25
|
+
onSuccess: async (...args) => {
|
|
26
|
+
await refetch()
|
|
27
|
+
await options?.onSuccess?.(...args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthClient,
|
|
3
|
+
useAuth,
|
|
4
|
+
useAuthMutation,
|
|
5
|
+
useSession
|
|
6
|
+
} from "@better-auth-ui/react"
|
|
7
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
8
|
+
import type {
|
|
9
|
+
UseAuthMutationOptions,
|
|
10
|
+
UseAuthMutationResult
|
|
11
|
+
} from "../auth/use-auth-mutation"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hook that creates a mutation for updating the authenticated user's profile.
|
|
15
|
+
*
|
|
16
|
+
* The mutation submits the name update, refetches the session on success,
|
|
17
|
+
* and displays success or error toasts.
|
|
18
|
+
*
|
|
19
|
+
* @returns The `useMutation` result.
|
|
20
|
+
*/
|
|
21
|
+
export function useUpdateUser(
|
|
22
|
+
options?: UseAuthMutationOptions<AuthClient["updateUser"]>
|
|
23
|
+
): UseAuthMutationResult<AuthClient["updateUser"]> {
|
|
24
|
+
const { authClient } = useAuth()
|
|
25
|
+
const { data: session, refetch } = useSession({ refetchOnMount: false })
|
|
26
|
+
const queryClient = useQueryClient()
|
|
27
|
+
|
|
28
|
+
return useAuthMutation({
|
|
29
|
+
authFn: authClient.updateUser,
|
|
30
|
+
options: {
|
|
31
|
+
...options,
|
|
32
|
+
onSuccess: async (data, variables, ...rest) => {
|
|
33
|
+
queryClient.setQueryData(["auth", "getSession"], {
|
|
34
|
+
...session,
|
|
35
|
+
user: { ...session?.user, ...variables }
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
refetch()
|
|
39
|
+
|
|
40
|
+
await options?.onSuccess?.(data, variables, ...rest)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|