@better-auth-ui/react 1.6.2 → 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.
Files changed (194) hide show
  1. package/dist/hooks/auth/use-authenticate.d.ts +30 -6
  2. package/dist/hooks/auth/use-is-username-available.d.ts +12 -11
  3. package/dist/hooks/auth/use-is-username-available.js +8 -7
  4. package/dist/hooks/auth/use-request-password-reset.d.ts +11 -15
  5. package/dist/hooks/auth/use-request-password-reset.js +8 -7
  6. package/dist/hooks/auth/use-reset-password.d.ts +13 -29
  7. package/dist/hooks/auth/use-reset-password.js +8 -7
  8. package/dist/hooks/auth/use-send-verification-email.d.ts +10 -14
  9. package/dist/hooks/auth/use-send-verification-email.js +8 -7
  10. package/dist/hooks/auth/use-session.d.ts +30 -4
  11. package/dist/hooks/auth/use-session.js +11 -10
  12. package/dist/hooks/auth/use-sign-in-email.d.ts +11 -37
  13. package/dist/hooks/auth/use-sign-in-email.js +11 -12
  14. package/dist/hooks/auth/use-sign-in-magic-link.d.ts +14 -18
  15. package/dist/hooks/auth/use-sign-in-magic-link.js +8 -7
  16. package/dist/hooks/auth/use-sign-in-passkey.d.ts +10 -47
  17. package/dist/hooks/auth/use-sign-in-passkey.js +11 -12
  18. package/dist/hooks/auth/use-sign-in-social.d.ts +30 -59
  19. package/dist/hooks/auth/use-sign-in-social.js +8 -7
  20. package/dist/hooks/auth/use-sign-in-username.d.ts +12 -40
  21. package/dist/hooks/auth/use-sign-in-username.js +11 -12
  22. package/dist/hooks/auth/use-sign-out.d.ts +10 -10
  23. package/dist/hooks/auth/use-sign-out.js +10 -12
  24. package/dist/hooks/auth/use-sign-up-email.d.ts +18 -101
  25. package/dist/hooks/auth/use-sign-up-email.js +11 -12
  26. package/dist/hooks/auth/use-user.d.ts +7 -5
  27. package/dist/hooks/settings/use-account-info.d.ts +9 -9
  28. package/dist/hooks/settings/use-account-info.js +13 -16
  29. package/dist/hooks/settings/use-add-passkey.d.ts +8 -30
  30. package/dist/hooks/settings/use-add-passkey.js +10 -11
  31. package/dist/hooks/settings/use-change-email.d.ts +11 -14
  32. package/dist/hooks/settings/use-change-email.js +11 -12
  33. package/dist/hooks/settings/use-change-password.d.ts +11 -43
  34. package/dist/hooks/settings/use-change-password.js +8 -7
  35. package/dist/hooks/settings/use-delete-passkey.d.ts +10 -12
  36. package/dist/hooks/settings/use-delete-passkey.js +11 -12
  37. package/dist/hooks/settings/use-delete-user.d.ts +13 -30
  38. package/dist/hooks/settings/use-delete-user.js +8 -7
  39. package/dist/hooks/settings/use-link-social.d.ts +22 -25
  40. package/dist/hooks/settings/use-link-social.js +8 -7
  41. package/dist/hooks/settings/use-list-accounts.d.ts +8 -6
  42. package/dist/hooks/settings/use-list-accounts.js +10 -16
  43. package/dist/hooks/settings/use-list-device-sessions.d.ts +29 -6
  44. package/dist/hooks/settings/use-list-device-sessions.js +10 -16
  45. package/dist/hooks/settings/use-list-sessions.d.ts +8 -5
  46. package/dist/hooks/settings/use-list-sessions.js +10 -16
  47. package/dist/hooks/settings/use-list-user-passkeys.d.ts +8 -5
  48. package/dist/hooks/settings/use-list-user-passkeys.js +10 -16
  49. package/dist/hooks/settings/use-revoke-multi-session.d.ts +11 -11
  50. package/dist/hooks/settings/use-revoke-multi-session.js +11 -12
  51. package/dist/hooks/settings/use-revoke-session.d.ts +11 -11
  52. package/dist/hooks/settings/use-revoke-session.js +11 -12
  53. package/dist/hooks/settings/use-set-active-session.d.ts +12 -29
  54. package/dist/hooks/settings/use-set-active-session.js +12 -13
  55. package/dist/hooks/settings/use-unlink-account.d.ts +12 -12
  56. package/dist/hooks/settings/use-unlink-account.js +11 -12
  57. package/dist/hooks/settings/use-update-user.d.ts +1178 -4
  58. package/dist/hooks/settings/use-update-user.js +17 -18
  59. package/dist/hooks/use-auth-mutation.d.ts +12 -0
  60. package/dist/hooks/use-auth-mutation.js +11 -0
  61. package/dist/hooks/use-auth-query.d.ts +14 -0
  62. package/dist/hooks/use-auth-query.js +15 -0
  63. package/dist/index.d.ts +2 -2
  64. package/dist/index.js +33 -33
  65. package/dist/mutations/auth/is-username-available-options.d.ts +19 -0
  66. package/dist/mutations/auth/is-username-available-options.js +7 -0
  67. package/dist/mutations/auth/request-password-reset-options.d.ts +15 -0
  68. package/dist/mutations/auth/request-password-reset-options.js +7 -0
  69. package/dist/mutations/auth/reset-password-options.d.ts +17 -0
  70. package/dist/mutations/auth/reset-password-options.js +7 -0
  71. package/dist/mutations/auth/send-verification-email-options.d.ts +15 -0
  72. package/dist/mutations/auth/send-verification-email-options.js +7 -0
  73. package/dist/mutations/auth/sign-in-email-options.d.ts +23 -0
  74. package/dist/mutations/auth/sign-in-email-options.js +11 -0
  75. package/dist/mutations/auth/sign-in-magic-link-options.d.ts +23 -0
  76. package/dist/mutations/auth/sign-in-magic-link-options.js +11 -0
  77. package/dist/mutations/auth/sign-in-passkey-options.d.ts +15 -0
  78. package/dist/mutations/auth/sign-in-passkey-options.js +11 -0
  79. package/dist/mutations/auth/sign-in-social-options.d.ts +61 -0
  80. package/dist/mutations/auth/sign-in-social-options.js +11 -0
  81. package/dist/mutations/auth/sign-in-username-options.d.ts +19 -0
  82. package/dist/mutations/auth/sign-in-username-options.js +11 -0
  83. package/dist/mutations/auth/sign-out-options.d.ts +12 -0
  84. package/dist/mutations/auth/sign-out-options.js +7 -0
  85. package/dist/mutations/auth/sign-up-email-options.d.ts +1180 -0
  86. package/dist/mutations/auth/sign-up-email-options.js +11 -0
  87. package/dist/mutations/auth-mutation-options.d.ts +25 -0
  88. package/dist/mutations/auth-mutation-options.js +19 -0
  89. package/dist/mutations/settings/add-passkey-options.d.ts +15 -0
  90. package/dist/mutations/settings/add-passkey-options.js +11 -0
  91. package/dist/mutations/settings/change-email-options.d.ts +15 -0
  92. package/dist/mutations/settings/change-email-options.js +7 -0
  93. package/dist/mutations/settings/change-password-options.d.ts +17 -0
  94. package/dist/mutations/settings/change-password-options.js +7 -0
  95. package/dist/mutations/settings/delete-passkey-options.d.ts +13 -0
  96. package/dist/mutations/settings/delete-passkey-options.js +11 -0
  97. package/dist/mutations/settings/delete-user-options.d.ts +20 -0
  98. package/dist/mutations/settings/delete-user-options.js +7 -0
  99. package/dist/mutations/settings/link-social-options.d.ts +39 -0
  100. package/dist/mutations/settings/link-social-options.js +7 -0
  101. package/dist/mutations/settings/revoke-multi-session-options.d.ts +13 -0
  102. package/dist/mutations/settings/revoke-multi-session-options.js +11 -0
  103. package/dist/mutations/settings/revoke-session-options.d.ts +13 -0
  104. package/dist/mutations/settings/revoke-session-options.js +7 -0
  105. package/dist/mutations/settings/set-active-session-options.d.ts +13 -0
  106. package/dist/mutations/settings/set-active-session-options.js +11 -0
  107. package/dist/mutations/settings/unlink-account-options.d.ts +15 -0
  108. package/dist/mutations/settings/unlink-account-options.js +7 -0
  109. package/dist/mutations/settings/update-user-options.d.ts +1182 -0
  110. package/dist/mutations/settings/update-user-options.js +7 -0
  111. package/dist/queries/auth/session-options.d.ts +110 -0
  112. package/dist/queries/auth/session-options.js +7 -0
  113. package/dist/queries/auth-query-options.d.ts +29 -0
  114. package/dist/queries/auth-query-options.js +17 -0
  115. package/dist/queries/settings/account-info-options.d.ts +32 -0
  116. package/dist/queries/settings/account-info-options.js +12 -0
  117. package/dist/queries/settings/list-accounts-options.d.ts +53 -0
  118. package/dist/queries/settings/list-accounts-options.js +12 -0
  119. package/dist/queries/settings/list-device-sessions-options.d.ts +99 -0
  120. package/dist/queries/settings/list-device-sessions-options.js +12 -0
  121. package/dist/queries/settings/list-sessions-options.d.ts +54 -0
  122. package/dist/queries/settings/list-sessions-options.js +12 -0
  123. package/dist/queries/settings/list-user-passkeys-options.d.ts +18 -0
  124. package/dist/queries/settings/list-user-passkeys-options.js +12 -0
  125. package/package.json +1 -1
  126. package/src/hooks/auth/use-authenticate.ts +7 -10
  127. package/src/hooks/auth/use-is-username-available.ts +17 -8
  128. package/src/hooks/auth/use-request-password-reset.ts +19 -8
  129. package/src/hooks/auth/use-reset-password.ts +19 -9
  130. package/src/hooks/auth/use-send-verification-email.ts +18 -8
  131. package/src/hooks/auth/use-session.ts +20 -16
  132. package/src/hooks/auth/use-sign-in-email.ts +23 -16
  133. package/src/hooks/auth/use-sign-in-magic-link.ts +18 -10
  134. package/src/hooks/auth/use-sign-in-passkey.ts +24 -18
  135. package/src/hooks/auth/use-sign-in-social.ts +18 -8
  136. package/src/hooks/auth/use-sign-in-username.ts +24 -18
  137. package/src/hooks/auth/use-sign-out.ts +18 -17
  138. package/src/hooks/auth/use-sign-up-email.ts +24 -18
  139. package/src/hooks/auth/use-user.ts +7 -8
  140. package/src/hooks/settings/use-account-info.ts +29 -20
  141. package/src/hooks/settings/use-add-passkey.ts +22 -17
  142. package/src/hooks/settings/use-change-email.ts +21 -17
  143. package/src/hooks/settings/use-change-password.ts +18 -8
  144. package/src/hooks/settings/use-delete-passkey.ts +21 -16
  145. package/src/hooks/settings/use-delete-user.ts +18 -8
  146. package/src/hooks/settings/use-link-social.ts +18 -8
  147. package/src/hooks/settings/use-list-accounts.ts +25 -15
  148. package/src/hooks/settings/use-list-device-sessions.ts +26 -21
  149. package/src/hooks/settings/use-list-sessions.ts +25 -14
  150. package/src/hooks/settings/use-list-user-passkeys.ts +25 -16
  151. package/src/hooks/settings/use-revoke-multi-session.ts +25 -16
  152. package/src/hooks/settings/use-revoke-session.ts +25 -16
  153. package/src/hooks/settings/use-set-active-session.ts +35 -24
  154. package/src/hooks/settings/use-unlink-account.ts +22 -15
  155. package/src/hooks/settings/use-update-user.ts +29 -22
  156. package/src/hooks/use-auth-mutation.ts +29 -0
  157. package/src/hooks/use-auth-query.ts +36 -0
  158. package/src/index.ts +2 -2
  159. package/src/mutations/auth/is-username-available-options.ts +18 -0
  160. package/src/mutations/auth/request-password-reset-options.ts +14 -0
  161. package/src/mutations/auth/reset-password-options.ts +14 -0
  162. package/src/mutations/auth/send-verification-email-options.ts +14 -0
  163. package/src/mutations/auth/sign-in-email-options.ts +19 -0
  164. package/src/mutations/auth/sign-in-magic-link-options.ts +15 -0
  165. package/src/mutations/auth/sign-in-passkey-options.ts +15 -0
  166. package/src/mutations/auth/sign-in-social-options.ts +19 -0
  167. package/src/mutations/auth/sign-in-username-options.ts +15 -0
  168. package/src/mutations/auth/sign-out-options.ts +11 -0
  169. package/src/mutations/auth/sign-up-email-options.ts +15 -0
  170. package/src/mutations/auth-mutation-options.ts +49 -0
  171. package/src/mutations/settings/add-passkey-options.ts +15 -0
  172. package/src/mutations/settings/change-email-options.ts +11 -0
  173. package/src/mutations/settings/change-password-options.ts +14 -0
  174. package/src/mutations/settings/delete-passkey-options.ts +15 -0
  175. package/src/mutations/settings/delete-user-options.ts +11 -0
  176. package/src/mutations/settings/link-social-options.ts +11 -0
  177. package/src/mutations/settings/revoke-multi-session-options.ts +15 -0
  178. package/src/mutations/settings/revoke-session-options.ts +14 -0
  179. package/src/mutations/settings/set-active-session-options.ts +15 -0
  180. package/src/mutations/settings/unlink-account-options.ts +14 -0
  181. package/src/mutations/settings/update-user-options.ts +15 -0
  182. package/src/queries/auth/session-options.ts +18 -0
  183. package/src/queries/auth-query-options.ts +34 -0
  184. package/src/queries/settings/account-info-options.ts +25 -0
  185. package/src/queries/settings/list-accounts-options.ts +26 -0
  186. package/src/queries/settings/list-device-sessions-options.ts +24 -0
  187. package/src/queries/settings/list-sessions-options.ts +23 -0
  188. package/src/queries/settings/list-user-passkeys-options.ts +23 -0
  189. package/dist/hooks/auth/use-auth-mutation.d.ts +0 -18
  190. package/dist/hooks/auth/use-auth-mutation.js +0 -13
  191. package/dist/hooks/auth/use-auth-query.d.ts +0 -24
  192. package/dist/hooks/auth/use-auth-query.js +0 -13
  193. package/src/hooks/auth/use-auth-mutation.ts +0 -56
  194. package/src/hooks/auth/use-auth-query.ts +0 -50
@@ -1,21 +1,31 @@
1
+ import { useMutation } from "@tanstack/react-query"
2
+
1
3
  import { useAuth } from "../../components/auth/auth-provider"
2
4
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "./use-auth-mutation"
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
+ >
7
15
 
8
16
  /**
9
17
  * Hook that creates a mutation to send a verification email.
10
18
  *
11
- * The mutation sends a verification email to the specified email address.
12
- *
19
+ * @param options - React Query options forwarded to `useMutation`.
13
20
  * @returns The `useMutation` result.
14
21
  */
15
22
  export function useSendVerificationEmail(
16
- options?: UseAuthMutationOptions<AuthClient["sendVerificationEmail"]>
23
+ options?: UseSendVerificationEmailOptions
17
24
  ) {
18
25
  const { authClient } = useAuth()
19
26
 
20
- return useAuthMutation({ authFn: authClient.sendVerificationEmail, options })
27
+ return useMutation({
28
+ ...sendVerificationEmailOptions(authClient),
29
+ ...options
30
+ })
21
31
  }
@@ -1,27 +1,31 @@
1
+ import { useQuery } from "@tanstack/react-query"
1
2
  import { useAuth } from "../../components/auth/auth-provider"
2
3
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthQueryOptions,
5
- type UseAuthQueryResult,
6
- useAuthQuery
7
- } from "./use-auth-query"
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
8
15
 
9
16
  /**
10
17
  * Retrieve the current authentication session.
11
18
  *
12
- * @param options - Options to merge into the React Query configuration for the session query.
13
- * @returns The React Query result for the session query: `data` contains session information, `isLoading`/`isFetching` indicate loading state, and `error` contains any fetch error.
19
+ * @param options - Better Auth params (`query`, `fetchOptions`) and React
20
+ * Query options forwarded to `useQuery`.
21
+ * @returns React Query result for the session.
14
22
  */
15
- export function useSession(
16
- options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
17
- ): UseAuthQueryResult<AuthClient["getSession"]> {
23
+ export function useSession(options?: UseSessionOptions) {
18
24
  const { authClient } = useAuth()
25
+ const { query, fetchOptions, ...queryOptions } = options ?? {}
19
26
 
20
- return useAuthQuery({
21
- authFn: authClient.getSession,
22
- options: {
23
- queryKey: ["auth", "getSession"],
24
- ...options
25
- }
27
+ return useQuery({
28
+ ...sessionOptions(authClient, { query, fetchOptions }),
29
+ ...queryOptions
26
30
  })
27
31
  }
@@ -1,11 +1,18 @@
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
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "./use-auth-mutation"
5
+ import { signInEmailOptions } from "../../mutations/auth/sign-in-email-options"
6
+ import { sessionOptions } from "../../queries/auth/session-options"
7
+
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
+ >
9
16
 
10
17
  /**
11
18
  * Hook that creates a mutation for email/password sign-in.
@@ -13,22 +20,22 @@ import {
13
20
  * The mutation sends an email/password sign-in request and
14
21
  * refetches the session on completion.
15
22
  *
23
+ * @param options - React Query options forwarded to `useMutation`.
16
24
  * @returns The `useMutation` result.
17
25
  */
18
- export function useSignInEmail(
19
- options?: UseAuthMutationOptions<AuthClient["signIn"]["email"]>
20
- ) {
26
+ export function useSignInEmail(options?: UseSignInEmailOptions) {
21
27
  const { authClient } = useAuth()
22
28
  const queryClient = useQueryClient()
23
29
 
24
- return useAuthMutation({
25
- authFn: authClient.signIn.email,
26
- options: {
27
- ...options,
28
- onSuccess: async (...args) => {
29
- queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
30
- await options?.onSuccess?.(...args)
31
- }
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)
32
39
  }
33
40
  })
34
41
  }
@@ -1,21 +1,29 @@
1
+ import { useMutation } from "@tanstack/react-query"
2
+
1
3
  import { useAuth } from "../../components/auth/auth-provider"
2
4
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "./use-auth-mutation"
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
+ >
7
15
 
8
16
  /**
9
17
  * Hook that creates a mutation for magic-link sign-in.
10
18
  *
11
- * The mutation sends a magic-link sign-in email to the specified address.
12
- *
19
+ * @param options - React Query options forwarded to `useMutation`.
13
20
  * @returns The `useMutation` result.
14
21
  */
15
- export function useSignInMagicLink(
16
- options?: UseAuthMutationOptions<AuthClient["signIn"]["magicLink"]>
17
- ) {
22
+ export function useSignInMagicLink(options?: UseSignInMagicLinkOptions) {
18
23
  const { authClient } = useAuth()
19
24
 
20
- return useAuthMutation({ authFn: authClient.signIn.magicLink, options })
25
+ return useMutation({
26
+ ...signInMagicLinkOptions(authClient),
27
+ ...options
28
+ })
21
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
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "./use-auth-mutation"
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
- * The mutation sends a passkey sign-in request and
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 useAuthMutation({
25
- authFn: authClient.signIn.passkey,
26
- options: {
27
- ...options,
28
- onSuccess: async (...args) => {
29
- queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
30
- await options?.onSuccess?.(...args)
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,21 +1,31 @@
1
+ import { useMutation } from "@tanstack/react-query"
2
+
1
3
  import { useAuth } from "../../components/auth/auth-provider"
2
4
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "./use-auth-mutation"
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
+ >
7
15
 
8
16
  /**
9
17
  * Hook that creates a mutation for social sign-in.
10
18
  *
11
19
  * The mutation initiates a social sign-in flow with the specified provider.
12
20
  *
21
+ * @param options - React Query options forwarded to `useMutation`.
13
22
  * @returns The `useMutation` result.
14
23
  */
15
- export function useSignInSocial(
16
- options?: UseAuthMutationOptions<AuthClient["signIn"]["social"]>
17
- ) {
24
+ export function useSignInSocial(options?: UseSignInSocialOptions) {
18
25
  const { authClient } = useAuth()
19
26
 
20
- return useAuthMutation({ authFn: authClient.signIn.social, options })
27
+ return useMutation({
28
+ ...signInSocialOptions(authClient),
29
+ ...options
30
+ })
21
31
  }
@@ -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
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "./use-auth-mutation"
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
+ >
9
16
 
10
17
  /**
11
18
  * Hook that creates a mutation for username/password sign-in.
12
19
  *
13
- * The mutation sends a username/password sign-in request and
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 useSignInUsername(
19
- options?: UseAuthMutationOptions<AuthClient["signIn"]["username"]>
20
- ) {
25
+ export function useSignInUsername(options?: UseSignInUsernameOptions) {
21
26
  const { authClient } = useAuth()
22
27
  const queryClient = useQueryClient()
23
28
 
24
- return useAuthMutation({
25
- authFn: authClient.signIn.username,
26
- options: {
27
- ...options,
28
- onSuccess: async (...args) => {
29
- queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
30
- await options?.onSuccess?.(...args)
31
- }
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)
32
38
  }
33
39
  })
34
40
  }
@@ -1,33 +1,34 @@
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
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "./use-auth-mutation"
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
+ >
9
13
 
10
14
  /**
11
15
  * Hook that creates a mutation for signing out.
12
16
  *
13
- * The mutation signs out the current user and removes auth queries from cache.
17
+ * Removes all cached auth queries on completion.
14
18
  *
19
+ * @param options - React Query options forwarded to `useMutation`.
15
20
  * @returns The `useMutation` result.
16
21
  */
17
- export function useSignOut(
18
- options?: UseAuthMutationOptions<AuthClient["signOut"]>
19
- ) {
22
+ export function useSignOut(options?: UseSignOutOptions) {
20
23
  const { authClient } = useAuth()
21
24
  const queryClient = useQueryClient()
22
25
 
23
- return useAuthMutation({
24
- authFn: authClient.signOut,
25
- options: {
26
- ...options,
27
- onSuccess: async (...args) => {
28
- queryClient.removeQueries({ queryKey: ["auth"] })
29
- await options?.onSuccess?.(...args)
30
- }
26
+ return useMutation({
27
+ ...signOutOptions(authClient),
28
+ ...options,
29
+ onSuccess: async (...args) => {
30
+ queryClient.removeQueries({ queryKey: ["auth"] })
31
+ await options?.onSuccess?.(...args)
31
32
  }
32
33
  })
33
34
  }
@@ -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
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "./use-auth-mutation"
5
+ import { signUpEmailOptions } from "../../mutations/auth/sign-up-email-options"
6
+ import { sessionOptions } from "../../queries/auth/session-options"
7
+
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
+ >
9
16
 
10
17
  /**
11
18
  * Hook that creates a mutation for email/password sign-up.
12
19
  *
13
- * The mutation sends an email/password sign-up request and
14
- * refetches the session on success.
20
+ * Resets the session query on success 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 useSignUpEmail(
19
- options?: UseAuthMutationOptions<AuthClient["signUp"]["email"]>
20
- ) {
25
+ export function useSignUpEmail(options?: UseSignUpEmailOptions) {
21
26
  const { authClient } = useAuth()
22
27
  const queryClient = useQueryClient()
23
28
 
24
- return useAuthMutation({
25
- authFn: authClient.signUp.email,
26
- options: {
27
- ...options,
28
- onSuccess: async (...args) => {
29
- queryClient.resetQueries({ queryKey: ["auth", "getSession"] })
30
- await options?.onSuccess?.(...args)
31
- }
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)
32
38
  }
33
39
  })
34
40
  }
@@ -1,16 +1,15 @@
1
- import type { AuthClient } from "../../lib/auth-client"
2
- import type { UseAuthQueryOptions } from "./use-auth-query"
3
- import { useSession } from "./use-session"
1
+ import { type UseSessionOptions, useSession } from "./use-session"
4
2
 
5
3
  /**
6
4
  * Retrieve the current authenticated user.
7
5
  *
8
- * @param options - Options to merge into the React Query configuration for the session query.
9
- * @returns The React Query result with `data` containing the user object from the session.
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.
10
11
  */
11
- export function useUser(
12
- options?: Partial<UseAuthQueryOptions<AuthClient["getSession"]>>
13
- ) {
12
+ export function useUser(options?: UseSessionOptions) {
14
13
  const { data, ...rest } = useSession(options)
15
14
 
16
15
  return {
@@ -1,31 +1,40 @@
1
+ import { skipToken, useQuery } from "@tanstack/react-query"
1
2
  import { useAuth } from "../../components/auth/auth-provider"
2
3
  import type { AuthClient } from "../../lib/auth-client"
3
- import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
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
4
16
 
5
17
  /**
6
- * Retrieve provider-specific account info for a given account ID.
18
+ * Retrieve provider-specific info for a linked account.
7
19
  *
8
- * Uses the `accountInfo` API endpoint to fetch detailed information
9
- * from the social provider. The provider is automatically detected
10
- * from the account ID.
20
+ * Keyed per-user; waits for the active session and `options.query.accountId`
21
+ * before firing.
11
22
  *
12
- * @param accountId - The provider-given account ID to fetch info for
13
- * @param options - Optional react-query options forwarded to `useQuery`
14
- * @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`.
15
25
  */
16
- export function useAccountInfo(
17
- accountId?: string,
18
- options?: Partial<UseAuthQueryOptions<AuthClient["accountInfo"]>>
19
- ) {
26
+ export function useAccountInfo(options?: UseAccountInfoOptions) {
20
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
21
34
 
22
- return useAuthQuery({
23
- authFn: authClient.accountInfo,
24
- params: { query: { accountId } },
25
- options: {
26
- queryKey: ["auth", "accountInfo", accountId],
27
- enabled: !!accountId,
28
- ...options
29
- }
35
+ return useQuery({
36
+ ...accountInfoOptions(authClient, userId, { query, fetchOptions }),
37
+ ...(disabled && { queryFn: skipToken }),
38
+ ...queryOptions
30
39
  })
31
40
  }
@@ -1,32 +1,37 @@
1
+ import { useMutation } from "@tanstack/react-query"
2
+
1
3
  import { useAuth } from "../../components/auth/auth-provider"
2
4
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
5
+ import { addPasskeyOptions } from "../../mutations/settings/add-passkey-options"
7
6
  import { useListUserPasskeys } from "./use-list-user-passkeys"
8
7
 
8
+ export type UseAddPasskeyParams = NonNullable<
9
+ Parameters<AuthClient["passkey"]["addPasskey"]>[0]
10
+ >
11
+
12
+ export type UseAddPasskeyOptions = Omit<
13
+ ReturnType<typeof addPasskeyOptions>,
14
+ "mutationKey" | "mutationFn"
15
+ >
16
+
9
17
  /**
10
- * Hook that creates a mutation for adding a new passkey.
18
+ * Hook that creates a mutation for registering a new passkey.
11
19
  *
12
- * Refetches the passkeys list on success.
20
+ * Refetches the user's passkey list on success.
13
21
  *
22
+ * @param options - React Query options forwarded to `useMutation`.
14
23
  * @returns The `useMutation` result.
15
24
  */
16
- export function useAddPasskey(
17
- options?: UseAuthMutationOptions<AuthClient["passkey"]["addPasskey"]>
18
- ) {
25
+ export function useAddPasskey(options?: UseAddPasskeyOptions) {
19
26
  const { authClient } = useAuth()
20
27
  const { refetch } = useListUserPasskeys()
21
28
 
22
- return useAuthMutation({
23
- authFn: authClient.passkey.addPasskey,
24
- options: {
25
- ...options,
26
- onSuccess: async (...args) => {
27
- await refetch()
28
- await options?.onSuccess?.(...args)
29
- }
29
+ return useMutation({
30
+ ...addPasskeyOptions(authClient),
31
+ ...options,
32
+ onSuccess: async (...args) => {
33
+ await refetch()
34
+ await options?.onSuccess?.(...args)
30
35
  }
31
36
  })
32
37
  }
@@ -1,33 +1,37 @@
1
+ import { useMutation } from "@tanstack/react-query"
2
+
1
3
  import { useAuth } from "../../components/auth/auth-provider"
2
4
  import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
5
+ import { changeEmailOptions } from "../../mutations/settings/change-email-options"
7
6
  import { useSession } from "../auth/use-session"
8
7
 
8
+ export type UseChangeEmailParams = NonNullable<
9
+ Parameters<AuthClient["changeEmail"]>[0]
10
+ >
11
+
12
+ export type UseChangeEmailOptions = Omit<
13
+ ReturnType<typeof changeEmailOptions>,
14
+ "mutationKey" | "mutationFn"
15
+ >
16
+
9
17
  /**
10
18
  * Hook that creates a mutation for changing the current user's email address.
11
19
  *
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.
20
+ * Refetches the session on success to surface the new email.
14
21
  *
22
+ * @param options - React Query options forwarded to `useMutation`.
15
23
  * @returns The `useMutation` result.
16
24
  */
17
- export function useChangeEmail(
18
- options?: UseAuthMutationOptions<AuthClient["changeEmail"]>
19
- ) {
25
+ export function useChangeEmail(options?: UseChangeEmailOptions) {
20
26
  const { authClient } = useAuth()
21
27
  const { refetch } = useSession({ refetchOnMount: false })
22
28
 
23
- return useAuthMutation({
24
- authFn: authClient.changeEmail,
25
- options: {
26
- ...options,
27
- onSuccess: async (...args) => {
28
- refetch()
29
- await options?.onSuccess?.(...args)
30
- }
29
+ return useMutation({
30
+ ...changeEmailOptions(authClient),
31
+ ...options,
32
+ onSuccess: async (...args) => {
33
+ await refetch()
34
+ await options?.onSuccess?.(...args)
31
35
  }
32
36
  })
33
37
  }