@better-auth-ui/react 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/dist/components/auth/auth-provider.d.ts +23 -8
  2. package/dist/components/auth/auth-provider.js +32 -17
  3. package/dist/components/{email → auth/email}/email-changed.js +2 -2
  4. package/dist/components/{email → auth/email}/email-localization.js +1 -1
  5. package/dist/components/{email → auth/email}/email-styles.js +1 -1
  6. package/dist/components/{email → auth/email}/email-verification.js +2 -2
  7. package/dist/components/{email → auth/email}/magic-link.js +2 -2
  8. package/dist/components/{email → auth/email}/new-device.js +2 -2
  9. package/dist/components/{email → auth/email}/otp-email.js +2 -2
  10. package/dist/components/{email → auth/email}/password-changed.js +2 -2
  11. package/dist/components/{email → auth/email}/reset-password.js +2 -2
  12. package/dist/email.d.ts +1 -0
  13. package/dist/email.js +11 -0
  14. package/dist/hooks/auth/use-authenticate.d.ts +6 -5
  15. package/dist/hooks/auth/use-authenticate.js +12 -12
  16. package/dist/hooks/auth/use-user.d.ts +18 -311
  17. package/dist/hooks/auth/use-user.js +5 -5
  18. package/dist/hooks/use-auth-mutation.d.ts +17 -0
  19. package/dist/hooks/use-auth-mutation.js +11 -0
  20. package/dist/hooks/use-auth-plugin.d.ts +31 -0
  21. package/dist/hooks/use-auth-plugin.js +10 -0
  22. package/dist/hooks/use-auth-query.d.ts +14 -0
  23. package/dist/hooks/use-auth-query.js +15 -0
  24. package/dist/index.d.ts +35 -34
  25. package/dist/index.js +74 -83
  26. package/dist/lib/auth-client.d.ts +23 -3687
  27. package/dist/lib/auth-plugin.d.ts +59 -0
  28. package/dist/lib/auth-server.d.ts +16 -0
  29. package/dist/mutations/auth/request-password-reset-mutation.d.ts +26 -0
  30. package/dist/mutations/auth/request-password-reset-mutation.js +24 -0
  31. package/dist/mutations/auth/reset-password-mutation.d.ts +25 -0
  32. package/dist/mutations/auth/reset-password-mutation.js +24 -0
  33. package/dist/mutations/auth/send-verification-email-mutation.d.ts +24 -0
  34. package/dist/mutations/auth/send-verification-email-mutation.js +24 -0
  35. package/dist/mutations/auth/sign-in-email-mutation.d.ts +71 -0
  36. package/dist/mutations/auth/sign-in-email-mutation.js +29 -0
  37. package/dist/mutations/auth/sign-in-social-mutation.d.ts +77 -0
  38. package/dist/mutations/auth/sign-in-social-mutation.js +24 -0
  39. package/dist/mutations/auth/sign-out-mutation.d.ts +25 -0
  40. package/dist/mutations/auth/sign-out-mutation.js +28 -0
  41. package/dist/mutations/auth/sign-up-email-mutation.d.ts +105 -0
  42. package/dist/mutations/auth/sign-up-email-mutation.js +29 -0
  43. package/dist/mutations/auth-mutation-options.d.ts +42 -0
  44. package/dist/mutations/auth-mutation-options.js +19 -0
  45. package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +24 -0
  46. package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +24 -0
  47. package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +25 -0
  48. package/dist/mutations/multi-session/revoke-multi-session-mutation.js +29 -0
  49. package/dist/mutations/multi-session/set-active-session-mutation.d.ts +62 -0
  50. package/dist/mutations/multi-session/set-active-session-mutation.js +31 -0
  51. package/dist/mutations/passkey/add-passkey-mutation.d.ts +71 -0
  52. package/dist/mutations/passkey/add-passkey-mutation.js +29 -0
  53. package/dist/mutations/passkey/delete-passkey-mutation.d.ts +25 -0
  54. package/dist/mutations/passkey/delete-passkey-mutation.js +29 -0
  55. package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +105 -0
  56. package/dist/mutations/passkey/sign-in-passkey-mutation.js +29 -0
  57. package/dist/mutations/settings/change-email-mutation.d.ts +25 -0
  58. package/dist/mutations/settings/change-email-mutation.js +29 -0
  59. package/dist/mutations/settings/change-password-mutation.d.ts +78 -0
  60. package/dist/mutations/settings/change-password-mutation.js +24 -0
  61. package/dist/mutations/settings/delete-user-mutation.d.ts +26 -0
  62. package/dist/mutations/settings/delete-user-mutation.js +24 -0
  63. package/dist/mutations/settings/link-social-mutation.d.ts +26 -0
  64. package/dist/mutations/settings/link-social-mutation.js +24 -0
  65. package/dist/mutations/settings/revoke-session-mutation.d.ts +25 -0
  66. package/dist/mutations/settings/revoke-session-mutation.js +29 -0
  67. package/dist/mutations/settings/unlink-account-mutation.d.ts +25 -0
  68. package/dist/mutations/settings/unlink-account-mutation.js +29 -0
  69. package/dist/mutations/settings/update-user-mutation.d.ts +25 -0
  70. package/dist/mutations/settings/update-user-mutation.js +35 -0
  71. package/dist/mutations/username/is-username-available-mutation.d.ts +27 -0
  72. package/dist/mutations/username/is-username-available-mutation.js +24 -0
  73. package/dist/mutations/username/sign-in-username-mutation.d.ts +75 -0
  74. package/dist/mutations/username/sign-in-username-mutation.js +29 -0
  75. package/dist/queries/auth/session-query.d.ts +71 -0
  76. package/dist/queries/auth/session-query.js +30 -0
  77. package/dist/queries/auth-query-options.d.ts +40 -0
  78. package/dist/queries/auth-query-options.js +17 -0
  79. package/dist/queries/multi-session/list-device-sessions-query.d.ts +76 -0
  80. package/dist/queries/multi-session/list-device-sessions-query.js +31 -0
  81. package/dist/queries/passkey/list-passkeys-query.d.ts +74 -0
  82. package/dist/queries/passkey/list-passkeys-query.js +31 -0
  83. package/dist/queries/settings/account-info-query.d.ts +85 -0
  84. package/dist/queries/settings/account-info-query.js +31 -0
  85. package/dist/queries/settings/list-accounts-query.d.ts +76 -0
  86. package/dist/queries/settings/list-accounts-query.js +31 -0
  87. package/dist/queries/settings/list-sessions-query.d.ts +74 -0
  88. package/dist/queries/settings/list-sessions-query.js +31 -0
  89. package/dist/server/queries/auth/session-query.d.ts +57 -0
  90. package/dist/server/queries/auth/session-query.js +13 -0
  91. package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +60 -0
  92. package/dist/server/queries/multi-session/list-device-sessions-query.js +12 -0
  93. package/dist/server/queries/passkey/list-passkeys-query.d.ts +60 -0
  94. package/dist/server/queries/passkey/list-passkeys-query.js +12 -0
  95. package/dist/server/queries/settings/account-info-query.d.ts +68 -0
  96. package/dist/server/queries/settings/account-info-query.js +12 -0
  97. package/dist/server/queries/settings/list-accounts-query.d.ts +60 -0
  98. package/dist/server/queries/settings/list-accounts-query.js +12 -0
  99. package/dist/server/queries/settings/list-sessions-query.d.ts +60 -0
  100. package/dist/server/queries/settings/list-sessions-query.js +12 -0
  101. package/dist/server.d.ts +7 -0
  102. package/dist/server.js +7 -0
  103. package/package.json +24 -22
  104. package/src/components/auth/auth-provider.tsx +87 -24
  105. package/src/components/{email → auth/email}/email-changed.tsx +1 -1
  106. package/src/components/{email → auth/email}/email-verification.tsx +1 -1
  107. package/src/components/{email → auth/email}/magic-link.tsx +1 -1
  108. package/src/components/{email → auth/email}/new-device.tsx +1 -1
  109. package/src/components/{email → auth/email}/otp-email.tsx +1 -1
  110. package/src/components/{email → auth/email}/password-changed.tsx +1 -1
  111. package/src/components/{email → auth/email}/reset-password.tsx +1 -1
  112. package/src/email.ts +1 -0
  113. package/src/hooks/auth/use-authenticate.ts +13 -10
  114. package/src/hooks/auth/use-user.ts +12 -8
  115. package/src/hooks/use-auth-mutation.ts +47 -0
  116. package/src/hooks/use-auth-plugin.ts +50 -0
  117. package/src/hooks/use-auth-query.ts +40 -0
  118. package/src/index.ts +35 -34
  119. package/src/lib/auth-client.ts +33 -31
  120. package/src/lib/auth-plugin.ts +75 -0
  121. package/src/lib/auth-server.ts +30 -0
  122. package/src/mutations/auth/request-password-reset-mutation.ts +58 -0
  123. package/src/mutations/auth/reset-password-mutation.ts +60 -0
  124. package/src/mutations/auth/send-verification-email-mutation.ts +58 -0
  125. package/src/mutations/auth/sign-in-email-mutation.ts +78 -0
  126. package/src/mutations/auth/sign-in-social-mutation.ts +64 -0
  127. package/src/mutations/auth/sign-out-mutation.ts +71 -0
  128. package/src/mutations/auth/sign-up-email-mutation.ts +74 -0
  129. package/src/mutations/auth-mutation-options.ts +94 -0
  130. package/src/mutations/magic-link/sign-in-magic-link-mutation.ts +59 -0
  131. package/src/mutations/multi-session/revoke-multi-session-mutation.ts +70 -0
  132. package/src/mutations/multi-session/set-active-session-mutation.ts +98 -0
  133. package/src/mutations/passkey/add-passkey-mutation.ts +66 -0
  134. package/src/mutations/passkey/delete-passkey-mutation.ts +66 -0
  135. package/src/mutations/passkey/sign-in-passkey-mutation.ts +74 -0
  136. package/src/mutations/settings/change-email-mutation.ts +67 -0
  137. package/src/mutations/settings/change-password-mutation.ts +59 -0
  138. package/src/mutations/settings/delete-user-mutation.ts +59 -0
  139. package/src/mutations/settings/link-social-mutation.ts +59 -0
  140. package/src/mutations/settings/revoke-session-mutation.ts +69 -0
  141. package/src/mutations/settings/unlink-account-mutation.ts +67 -0
  142. package/src/mutations/settings/update-user-mutation.ts +82 -0
  143. package/src/mutations/username/is-username-available-mutation.ts +62 -0
  144. package/src/mutations/username/sign-in-username-mutation.ts +74 -0
  145. package/src/queries/auth/session-query.ts +135 -0
  146. package/src/queries/auth-query-options.ts +83 -0
  147. package/src/queries/multi-session/list-device-sessions-query.ts +177 -0
  148. package/src/queries/passkey/list-passkeys-query.ts +154 -0
  149. package/src/queries/settings/account-info-query.ts +158 -0
  150. package/src/queries/settings/list-accounts-query.ts +156 -0
  151. package/src/queries/settings/list-sessions-query.ts +154 -0
  152. package/src/server/queries/auth/session-query.ts +94 -0
  153. package/src/server/queries/multi-session/list-device-sessions-query.ts +102 -0
  154. package/src/server/queries/passkey/list-passkeys-query.ts +100 -0
  155. package/src/server/queries/settings/account-info-query.ts +101 -0
  156. package/src/server/queries/settings/list-accounts-query.ts +101 -0
  157. package/src/server/queries/settings/list-sessions-query.ts +101 -0
  158. package/src/server.ts +7 -0
  159. package/dist/core.d.ts +0 -1
  160. package/dist/core.js +0 -1
  161. package/dist/hooks/auth/use-auth-mutation.d.ts +0 -18
  162. package/dist/hooks/auth/use-auth-mutation.js +0 -13
  163. package/dist/hooks/auth/use-auth-query.d.ts +0 -24
  164. package/dist/hooks/auth/use-auth-query.js +0 -13
  165. package/dist/hooks/auth/use-is-username-available.d.ts +0 -19
  166. package/dist/hooks/auth/use-is-username-available.js +0 -12
  167. package/dist/hooks/auth/use-request-password-reset.d.ts +0 -25
  168. package/dist/hooks/auth/use-request-password-reset.js +0 -12
  169. package/dist/hooks/auth/use-reset-password.d.ts +0 -39
  170. package/dist/hooks/auth/use-reset-password.js +0 -12
  171. package/dist/hooks/auth/use-send-verification-email.d.ts +0 -23
  172. package/dist/hooks/auth/use-send-verification-email.js +0 -12
  173. package/dist/hooks/auth/use-session.d.ts +0 -9
  174. package/dist/hooks/auth/use-session.js +0 -15
  175. package/dist/hooks/auth/use-sign-in-email.d.ts +0 -52
  176. package/dist/hooks/auth/use-sign-in-email.js +0 -18
  177. package/dist/hooks/auth/use-sign-in-magic-link.d.ts +0 -31
  178. package/dist/hooks/auth/use-sign-in-magic-link.js +0 -12
  179. package/dist/hooks/auth/use-sign-in-passkey.d.ts +0 -58
  180. package/dist/hooks/auth/use-sign-in-passkey.js +0 -18
  181. package/dist/hooks/auth/use-sign-in-social.d.ts +0 -92
  182. package/dist/hooks/auth/use-sign-in-social.js +0 -12
  183. package/dist/hooks/auth/use-sign-in-username.d.ts +0 -53
  184. package/dist/hooks/auth/use-sign-in-username.js +0 -18
  185. package/dist/hooks/auth/use-sign-out.d.ts +0 -18
  186. package/dist/hooks/auth/use-sign-out.js +0 -18
  187. package/dist/hooks/auth/use-sign-up-email.d.ts +0 -1269
  188. package/dist/hooks/auth/use-sign-up-email.js +0 -18
  189. package/dist/hooks/settings/use-account-info.d.ts +0 -17
  190. package/dist/hooks/settings/use-account-info.js +0 -21
  191. package/dist/hooks/settings/use-add-passkey.d.ts +0 -43
  192. package/dist/hooks/settings/use-add-passkey.js +0 -18
  193. package/dist/hooks/settings/use-change-email.d.ts +0 -24
  194. package/dist/hooks/settings/use-change-email.js +0 -18
  195. package/dist/hooks/settings/use-change-password.d.ts +0 -53
  196. package/dist/hooks/settings/use-change-password.js +0 -12
  197. package/dist/hooks/settings/use-delete-passkey.d.ts +0 -21
  198. package/dist/hooks/settings/use-delete-passkey.js +0 -18
  199. package/dist/hooks/settings/use-delete-user.d.ts +0 -41
  200. package/dist/hooks/settings/use-delete-user.js +0 -12
  201. package/dist/hooks/settings/use-link-social.d.ts +0 -46
  202. package/dist/hooks/settings/use-link-social.js +0 -12
  203. package/dist/hooks/settings/use-list-accounts.d.ts +0 -20
  204. package/dist/hooks/settings/use-list-accounts.js +0 -21
  205. package/dist/hooks/settings/use-list-device-sessions.d.ts +0 -11
  206. package/dist/hooks/settings/use-list-device-sessions.js +0 -21
  207. package/dist/hooks/settings/use-list-sessions.d.ts +0 -20
  208. package/dist/hooks/settings/use-list-sessions.js +0 -21
  209. package/dist/hooks/settings/use-list-user-passkeys.d.ts +0 -11
  210. package/dist/hooks/settings/use-list-user-passkeys.js +0 -21
  211. package/dist/hooks/settings/use-revoke-multi-session.d.ts +0 -19
  212. package/dist/hooks/settings/use-revoke-multi-session.js +0 -18
  213. package/dist/hooks/settings/use-revoke-session.d.ts +0 -19
  214. package/dist/hooks/settings/use-revoke-session.js +0 -18
  215. package/dist/hooks/settings/use-set-active-session.d.ts +0 -37
  216. package/dist/hooks/settings/use-set-active-session.js +0 -21
  217. package/dist/hooks/settings/use-unlink-account.d.ts +0 -21
  218. package/dist/hooks/settings/use-unlink-account.js +0 -18
  219. package/dist/hooks/settings/use-update-user.d.ts +0 -11
  220. package/dist/hooks/settings/use-update-user.js +0 -25
  221. package/dist/lib/auth-client.js +0 -11
  222. package/dist/lib/auth-config.d.ts +0 -43
  223. package/dist/lib/auth-context.d.ts +0 -2
  224. package/dist/lib/auth-context.js +0 -6
  225. package/src/core.ts +0 -1
  226. package/src/hooks/auth/use-auth-mutation.ts +0 -56
  227. package/src/hooks/auth/use-auth-query.ts +0 -50
  228. package/src/hooks/auth/use-is-username-available.ts +0 -22
  229. package/src/hooks/auth/use-request-password-reset.ts +0 -22
  230. package/src/hooks/auth/use-reset-password.ts +0 -21
  231. package/src/hooks/auth/use-send-verification-email.ts +0 -21
  232. package/src/hooks/auth/use-session.ts +0 -27
  233. package/src/hooks/auth/use-sign-in-email.ts +0 -34
  234. package/src/hooks/auth/use-sign-in-magic-link.ts +0 -21
  235. package/src/hooks/auth/use-sign-in-passkey.ts +0 -34
  236. package/src/hooks/auth/use-sign-in-social.ts +0 -21
  237. package/src/hooks/auth/use-sign-in-username.ts +0 -34
  238. package/src/hooks/auth/use-sign-out.ts +0 -33
  239. package/src/hooks/auth/use-sign-up-email.ts +0 -34
  240. package/src/hooks/settings/use-account-info.ts +0 -31
  241. package/src/hooks/settings/use-add-passkey.ts +0 -32
  242. package/src/hooks/settings/use-change-email.ts +0 -33
  243. package/src/hooks/settings/use-change-password.ts +0 -19
  244. package/src/hooks/settings/use-delete-passkey.ts +0 -32
  245. package/src/hooks/settings/use-delete-user.ts +0 -19
  246. package/src/hooks/settings/use-link-social.ts +0 -19
  247. package/src/hooks/settings/use-list-accounts.ts +0 -29
  248. package/src/hooks/settings/use-list-device-sessions.ts +0 -34
  249. package/src/hooks/settings/use-list-sessions.ts +0 -28
  250. package/src/hooks/settings/use-list-user-passkeys.ts +0 -30
  251. package/src/hooks/settings/use-revoke-multi-session.ts +0 -30
  252. package/src/hooks/settings/use-revoke-session.ts +0 -30
  253. package/src/hooks/settings/use-set-active-session.ts +0 -47
  254. package/src/hooks/settings/use-unlink-account.ts +0 -30
  255. package/src/hooks/settings/use-update-user.ts +0 -43
  256. package/src/lib/auth-config.ts +0 -48
  257. package/src/lib/auth-context.ts +0 -6
  258. /package/dist/components/{email → auth/email}/email-changed.d.ts +0 -0
  259. /package/dist/components/{email → auth/email}/email-localization.d.ts +0 -0
  260. /package/dist/components/{email → auth/email}/email-styles.d.ts +0 -0
  261. /package/dist/components/{email → auth/email}/email-verification.d.ts +0 -0
  262. /package/dist/components/{email → auth/email}/index.d.ts +0 -0
  263. /package/dist/components/{email → auth/email}/index.js +0 -0
  264. /package/dist/components/{email → auth/email}/magic-link.d.ts +0 -0
  265. /package/dist/components/{email → auth/email}/new-device.d.ts +0 -0
  266. /package/dist/components/{email → auth/email}/otp-email.d.ts +0 -0
  267. /package/dist/components/{email → auth/email}/password-changed.d.ts +0 -0
  268. /package/dist/components/{email → auth/email}/reset-password.d.ts +0 -0
  269. /package/src/components/{email → auth/email}/email-localization.tsx +0 -0
  270. /package/src/components/{email → auth/email}/email-styles.tsx +0 -0
  271. /package/src/components/{email → auth/email}/index.ts +0 -0
@@ -1,31 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
4
-
5
- /**
6
- * Retrieve provider-specific account info for a given account ID.
7
- *
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.
11
- *
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
15
- */
16
- export function useAccountInfo(
17
- accountId?: string,
18
- options?: Partial<UseAuthQueryOptions<AuthClient["accountInfo"]>>
19
- ) {
20
- const { authClient } = useAuth()
21
-
22
- return useAuthQuery({
23
- authFn: authClient.accountInfo,
24
- params: { query: { accountId } },
25
- options: {
26
- queryKey: ["auth", "accountInfo", accountId],
27
- enabled: !!accountId,
28
- ...options
29
- }
30
- })
31
- }
@@ -1,32 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useListUserPasskeys } from "./use-list-user-passkeys"
8
-
9
- /**
10
- * Hook that creates a mutation for adding a new passkey.
11
- *
12
- * Refetches the passkeys list on success.
13
- *
14
- * @returns The `useMutation` result.
15
- */
16
- export function useAddPasskey(
17
- options?: UseAuthMutationOptions<AuthClient["passkey"]["addPasskey"]>
18
- ) {
19
- const { authClient } = useAuth()
20
- const { refetch } = useListUserPasskeys()
21
-
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
- }
30
- }
31
- })
32
- }
@@ -1,33 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useSession } from "../auth/use-session"
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
- }
@@ -1,19 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
-
8
- /**
9
- * Hook that creates a mutation for changing the authenticated user's password.
10
- *
11
- * @returns The `useMutation` result.
12
- */
13
- export function useChangePassword(
14
- options?: UseAuthMutationOptions<AuthClient["changePassword"]>
15
- ) {
16
- const { authClient } = useAuth()
17
-
18
- return useAuthMutation({ authFn: authClient.changePassword, options })
19
- }
@@ -1,32 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useListUserPasskeys } from "./use-list-user-passkeys"
8
-
9
- /**
10
- * Hook that creates a mutation for deleting a passkey.
11
- *
12
- * Refetches the passkeys list on success.
13
- *
14
- * @returns The `useMutation` result.
15
- */
16
- export function useDeletePasskey(
17
- options?: UseAuthMutationOptions<AuthClient["passkey"]["deletePasskey"]>
18
- ) {
19
- const { authClient } = useAuth()
20
- const { refetch } = useListUserPasskeys()
21
-
22
- return useAuthMutation({
23
- authFn: authClient.passkey.deletePasskey,
24
- options: {
25
- ...options,
26
- onSuccess: async (...args) => {
27
- await refetch()
28
- await options?.onSuccess?.(...args)
29
- }
30
- }
31
- })
32
- }
@@ -1,19 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
-
8
- /**
9
- * Hook that creates a mutation for deleting the authenticated user account.
10
- *
11
- * @returns The `useMutation` result.
12
- */
13
- export function useDeleteUser(
14
- options?: UseAuthMutationOptions<AuthClient["deleteUser"]>
15
- ) {
16
- const { authClient } = useAuth()
17
-
18
- return useAuthMutation({ authFn: authClient.deleteUser, options })
19
- }
@@ -1,19 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } 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
- }
@@ -1,29 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
4
- import { useSession } from "../auth/use-session"
5
-
6
- /**
7
- * Retrieve the current user's linked social accounts.
8
- *
9
- * The query runs only when at least one social provider is configured and a session exists.
10
- * The provided `options` are forwarded to both `useSession` and `useQuery`, allowing customization of initial data and query behavior.
11
- *
12
- * @param options - Optional react-query / initial-data options forwarded to `useSession` and `useQuery`
13
- * @returns The react-query result containing linked accounts data, loading state, and error state
14
- */
15
- export function useListAccounts(
16
- options?: Partial<UseAuthQueryOptions<AuthClient["listAccounts"]>>
17
- ) {
18
- const { authClient } = useAuth()
19
- const { data: session } = useSession({ refetchOnMount: false })
20
-
21
- return useAuthQuery({
22
- authFn: authClient.listAccounts,
23
- options: {
24
- queryKey: ["auth", "listAccounts", session?.user.id],
25
- enabled: !!session,
26
- ...options
27
- }
28
- })
29
- }
@@ -1,34 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthQueryOptions,
5
- type UseAuthQueryResult,
6
- useAuthQuery
7
- } from "../auth/use-auth-query"
8
- import { useSession } from "../auth/use-session"
9
-
10
- /**
11
- * Retrieve device sessions for multi-session account switching.
12
- *
13
- * The query is enabled only when `multiSession` is true and session data is available.
14
- *
15
- * @param options - Optional React Query options to customize the query behavior.
16
- * @returns The React Query result for the device sessions list; `data` is the array of device session objects and includes loading and error states.
17
- */
18
- export function useListDeviceSessions(
19
- options?: Partial<
20
- UseAuthQueryOptions<AuthClient["multiSession"]["listDeviceSessions"]>
21
- >
22
- ): UseAuthQueryResult<AuthClient["multiSession"]["listDeviceSessions"]> {
23
- const { authClient } = useAuth()
24
- const { data: session } = useSession({ refetchOnMount: false })
25
-
26
- return useAuthQuery({
27
- authFn: authClient.multiSession.listDeviceSessions,
28
- options: {
29
- queryKey: ["auth", "multiSession", "listDeviceSessions"],
30
- enabled: !!session,
31
- ...options
32
- }
33
- })
34
- }
@@ -1,28 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
4
- import { useSession } from "../auth/use-session"
5
-
6
- /**
7
- * Retrieve the active sessions (devices where the current user is signed in).
8
- *
9
- * The underlying query is enabled only when session data is available.
10
- *
11
- * @param options - Optional React Query options to customize the query behavior.
12
- * @returns The React Query result for the sessions list; `data` is the array of session objects, and the result includes loading and error states.
13
- */
14
- export function useListSessions(
15
- options?: Partial<UseAuthQueryOptions<AuthClient["listSessions"]>>
16
- ) {
17
- const { authClient } = useAuth()
18
- const { data: session } = useSession({ refetchOnMount: false })
19
-
20
- return useAuthQuery({
21
- authFn: authClient.listSessions,
22
- options: {
23
- queryKey: ["auth", "listSessions", session?.user.id],
24
- enabled: !!session,
25
- ...options
26
- }
27
- })
28
- }
@@ -1,30 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import { type UseAuthQueryOptions, useAuthQuery } from "../auth/use-auth-query"
4
- import { useSession } from "../auth/use-session"
5
-
6
- /**
7
- * Retrieve the passkeys registered for the current user.
8
- *
9
- * The underlying query is enabled only when session data is available.
10
- *
11
- * @param options - Optional React Query options to customize the query behavior.
12
- * @returns The React Query result for the passkeys list.
13
- */
14
- export function useListUserPasskeys(
15
- options?: Partial<
16
- UseAuthQueryOptions<AuthClient["passkey"]["listUserPasskeys"]>
17
- >
18
- ) {
19
- const { authClient } = useAuth()
20
- const { data: session } = useSession({ refetchOnMount: false })
21
-
22
- return useAuthQuery({
23
- authFn: authClient.passkey.listUserPasskeys,
24
- options: {
25
- queryKey: ["auth", "listUserPasskeys", session?.user.id],
26
- enabled: !!session,
27
- ...options
28
- }
29
- })
30
- }
@@ -1,30 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useListDeviceSessions } from "./use-list-device-sessions"
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
- }
@@ -1,30 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useListSessions } from "./use-list-sessions"
8
-
9
- /**
10
- * Hook that creates a mutation for revoking a user session.
11
- *
12
- * @returns The `useMutation` result.
13
- */
14
- export function useRevokeSession(
15
- options?: UseAuthMutationOptions<AuthClient["revokeSession"]>
16
- ) {
17
- const { authClient } = useAuth()
18
- const { refetch } = useListSessions({ refetchOnMount: false })
19
-
20
- return useAuthMutation({
21
- authFn: authClient.revokeSession,
22
- options: {
23
- ...options,
24
- onSuccess: async (...args) => {
25
- await refetch()
26
- await options?.onSuccess?.(...args)
27
- }
28
- }
29
- })
30
- }
@@ -1,47 +0,0 @@
1
- import { useQueryClient } from "@tanstack/react-query"
2
-
3
- import { useAuth } from "../../components/auth/auth-provider"
4
- import type { AuthClient } from "../../lib/auth-client"
5
- import {
6
- type UseAuthMutationOptions,
7
- useAuthMutation
8
- } from "../auth/use-auth-mutation"
9
- import { useSession } from "../auth/use-session"
10
- import { useListDeviceSessions } from "./use-list-device-sessions"
11
-
12
- /**
13
- * Hook that sets an active device session in multi-session mode.
14
- *
15
- * @returns The `useMutation` result.
16
- */
17
- export function useSetActiveSession(
18
- options?: UseAuthMutationOptions<AuthClient["multiSession"]["setActive"]>
19
- ) {
20
- const queryClient = useQueryClient()
21
- const { authClient } = useAuth()
22
-
23
- const { refetch: refetchSession } = useSession({ refetchOnMount: false })
24
- const { data: deviceSessions, refetch: refetchDeviceSessions } =
25
- useListDeviceSessions({ refetchOnMount: false })
26
-
27
- return useAuthMutation({
28
- authFn: authClient.multiSession.setActive,
29
- options: {
30
- ...options,
31
- onSuccess: async (data, { sessionToken }, ...args) => {
32
- const deviceSession = deviceSessions?.find(
33
- (session) => session.session.token === sessionToken
34
- )
35
-
36
- if (deviceSession)
37
- queryClient.setQueryData(["auth", "getSession"], deviceSession)
38
-
39
- window.scrollTo({ top: 0 })
40
-
41
- await refetchSession()
42
- await refetchDeviceSessions()
43
- await options?.onSuccess?.(data, { sessionToken }, ...args)
44
- }
45
- }
46
- })
47
- }
@@ -1,30 +0,0 @@
1
- import { useAuth } from "../../components/auth/auth-provider"
2
- import type { AuthClient } from "../../lib/auth-client"
3
- import {
4
- type UseAuthMutationOptions,
5
- useAuthMutation
6
- } from "../auth/use-auth-mutation"
7
- import { useListAccounts } from "./use-list-accounts"
8
-
9
- /**
10
- * Hook that creates a mutation for unlinking a social provider from the current user.
11
- *
12
- * @returns The `useMutation` result.
13
- */
14
- export function useUnlinkAccount(
15
- options?: UseAuthMutationOptions<AuthClient["unlinkAccount"]>
16
- ) {
17
- const { authClient } = useAuth()
18
- const { refetch } = useListAccounts({ refetchOnMount: false })
19
-
20
- return useAuthMutation({
21
- authFn: authClient.unlinkAccount,
22
- options: {
23
- ...options,
24
- onSuccess: async (...args) => {
25
- await refetch()
26
- await options?.onSuccess?.(...args)
27
- }
28
- }
29
- })
30
- }
@@ -1,43 +0,0 @@
1
- import { useQueryClient } from "@tanstack/react-query"
2
-
3
- import { useAuth } from "../../components/auth/auth-provider"
4
- import type { AuthClient } from "../../lib/auth-client"
5
- import {
6
- type UseAuthMutationOptions,
7
- type UseAuthMutationResult,
8
- useAuthMutation
9
- } from "../auth/use-auth-mutation"
10
- import { useSession } from "../auth/use-session"
11
-
12
- /**
13
- * Hook that creates a mutation for updating the authenticated user's profile.
14
- *
15
- * The mutation submits the name update, refetches the session on success,
16
- * and displays success or error toasts.
17
- *
18
- * @returns The `useMutation` result.
19
- */
20
- export function useUpdateUser(
21
- options?: UseAuthMutationOptions<AuthClient["updateUser"]>
22
- ): UseAuthMutationResult<AuthClient["updateUser"]> {
23
- const { authClient } = useAuth()
24
- const { data: session, refetch } = useSession({ refetchOnMount: false })
25
- const queryClient = useQueryClient()
26
-
27
- return useAuthMutation({
28
- authFn: authClient.updateUser,
29
- options: {
30
- ...options,
31
- onSuccess: async (data, variables, ...rest) => {
32
- queryClient.setQueryData(["auth", "getSession"], {
33
- ...session,
34
- user: { ...session?.user, ...variables }
35
- })
36
-
37
- refetch()
38
-
39
- await options?.onSuccess?.(data, variables, ...rest)
40
- }
41
- }
42
- })
43
- }
@@ -1,48 +0,0 @@
1
- import type { AuthConfig as BaseAuthConfig } from "@better-auth-ui/core"
2
- import type { ComponentType, PropsWithChildren } from "react"
3
- import type { AnyAuthClient, AuthClient } from "./auth-client"
4
-
5
- /**
6
- * Extends the base AuthConfig with React-specific requirements including
7
- * an authClient instance and a Link component for navigation.
8
- *
9
- * Users can augment this interface to provide their own auth client type:
10
- * @example
11
- * ```ts
12
- * declare module "@better-auth-ui/react" {
13
- * interface AuthConfig {
14
- * AuthClient: typeof authClient
15
- * }
16
- * }
17
- * ```
18
- */
19
- export interface AuthConfig extends BaseAuthConfig {
20
- authClient: AuthClient
21
- /**
22
- * React component for rendering links
23
- * @remarks `LinkComponent`
24
- */
25
- Link: ComponentType<
26
- PropsWithChildren<{ className?: string; href: string; to?: string }>
27
- >
28
- }
29
-
30
- // biome-ignore lint/suspicious/noExplicitAny: required for generic utility type
31
- type DeepPartial<T> = T extends (...args: any[]) => any
32
- ? T
33
- : T extends object
34
- ? {
35
- [P in keyof T]?: DeepPartial<T[P]>
36
- }
37
- : T
38
-
39
- /**
40
- * Partial AuthConfig with any Better Auth client instance.
41
- */
42
- export type AnyAuthConfig = DeepPartial<Omit<AuthConfig, "authClient">> & {
43
- /**
44
- * Better Auth client instance
45
- * @remarks `AuthClient`
46
- */
47
- authClient?: AnyAuthClient
48
- }
@@ -1,6 +0,0 @@
1
- "use client"
2
-
3
- import { createContext } from "react"
4
- import type { AuthConfig } from "./auth-config"
5
-
6
- export const AuthContext = createContext<AuthConfig | undefined>(undefined)
File without changes
File without changes