@better-auth-ui/react 1.6.3 → 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 (346) 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 +5 -28
  15. package/dist/hooks/auth/use-authenticate.js +12 -12
  16. package/dist/hooks/auth/use-user.d.ts +19 -314
  17. package/dist/hooks/auth/use-user.js +5 -5
  18. package/dist/hooks/use-auth-mutation.d.ts +12 -7
  19. package/dist/hooks/use-auth-plugin.d.ts +31 -0
  20. package/dist/hooks/use-auth-plugin.js +10 -0
  21. package/dist/hooks/use-auth-query.d.ts +3 -3
  22. package/dist/index.d.ts +33 -32
  23. package/dist/index.js +74 -83
  24. package/dist/lib/auth-client.d.ts +23 -3687
  25. package/dist/lib/auth-plugin.d.ts +59 -0
  26. package/dist/lib/auth-server.d.ts +16 -0
  27. package/dist/mutations/auth/request-password-reset-mutation.d.ts +26 -0
  28. package/dist/mutations/auth/request-password-reset-mutation.js +24 -0
  29. package/dist/mutations/auth/reset-password-mutation.d.ts +25 -0
  30. package/dist/mutations/auth/reset-password-mutation.js +24 -0
  31. package/dist/mutations/auth/send-verification-email-mutation.d.ts +24 -0
  32. package/dist/mutations/auth/send-verification-email-mutation.js +24 -0
  33. package/dist/mutations/auth/sign-in-email-mutation.d.ts +71 -0
  34. package/dist/mutations/auth/sign-in-email-mutation.js +29 -0
  35. package/dist/mutations/auth/sign-in-social-mutation.d.ts +77 -0
  36. package/dist/mutations/auth/sign-in-social-mutation.js +24 -0
  37. package/dist/mutations/auth/sign-out-mutation.d.ts +25 -0
  38. package/dist/mutations/auth/sign-out-mutation.js +28 -0
  39. package/dist/mutations/auth/sign-up-email-mutation.d.ts +105 -0
  40. package/dist/mutations/auth/sign-up-email-mutation.js +29 -0
  41. package/dist/mutations/auth-mutation-options.d.ts +37 -20
  42. package/dist/mutations/auth-mutation-options.js +2 -2
  43. package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +24 -0
  44. package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +24 -0
  45. package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +25 -0
  46. package/dist/mutations/multi-session/revoke-multi-session-mutation.js +29 -0
  47. package/dist/mutations/multi-session/set-active-session-mutation.d.ts +62 -0
  48. package/dist/mutations/multi-session/set-active-session-mutation.js +31 -0
  49. package/dist/mutations/passkey/add-passkey-mutation.d.ts +71 -0
  50. package/dist/mutations/passkey/add-passkey-mutation.js +29 -0
  51. package/dist/mutations/passkey/delete-passkey-mutation.d.ts +25 -0
  52. package/dist/mutations/passkey/delete-passkey-mutation.js +29 -0
  53. package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +105 -0
  54. package/dist/mutations/passkey/sign-in-passkey-mutation.js +29 -0
  55. package/dist/mutations/settings/change-email-mutation.d.ts +25 -0
  56. package/dist/mutations/settings/change-email-mutation.js +29 -0
  57. package/dist/mutations/settings/change-password-mutation.d.ts +78 -0
  58. package/dist/mutations/settings/change-password-mutation.js +24 -0
  59. package/dist/mutations/settings/delete-user-mutation.d.ts +26 -0
  60. package/dist/mutations/settings/delete-user-mutation.js +24 -0
  61. package/dist/mutations/settings/link-social-mutation.d.ts +26 -0
  62. package/dist/mutations/settings/link-social-mutation.js +24 -0
  63. package/dist/mutations/settings/revoke-session-mutation.d.ts +25 -0
  64. package/dist/mutations/settings/revoke-session-mutation.js +29 -0
  65. package/dist/mutations/settings/unlink-account-mutation.d.ts +25 -0
  66. package/dist/mutations/settings/unlink-account-mutation.js +29 -0
  67. package/dist/mutations/settings/update-user-mutation.d.ts +25 -0
  68. package/dist/mutations/settings/update-user-mutation.js +35 -0
  69. package/dist/mutations/username/is-username-available-mutation.d.ts +27 -0
  70. package/dist/mutations/username/is-username-available-mutation.js +24 -0
  71. package/dist/mutations/username/sign-in-username-mutation.d.ts +75 -0
  72. package/dist/mutations/username/sign-in-username-mutation.js +29 -0
  73. package/dist/queries/auth/session-query.d.ts +71 -0
  74. package/dist/queries/auth/session-query.js +30 -0
  75. package/dist/queries/auth-query-options.d.ts +26 -15
  76. package/dist/queries/multi-session/list-device-sessions-query.d.ts +76 -0
  77. package/dist/queries/multi-session/list-device-sessions-query.js +31 -0
  78. package/dist/queries/passkey/list-passkeys-query.d.ts +74 -0
  79. package/dist/queries/passkey/list-passkeys-query.js +31 -0
  80. package/dist/queries/settings/account-info-query.d.ts +85 -0
  81. package/dist/queries/settings/account-info-query.js +31 -0
  82. package/dist/queries/settings/list-accounts-query.d.ts +76 -0
  83. package/dist/queries/settings/list-accounts-query.js +31 -0
  84. package/dist/queries/settings/list-sessions-query.d.ts +74 -0
  85. package/dist/queries/settings/list-sessions-query.js +31 -0
  86. package/dist/server/queries/auth/session-query.d.ts +57 -0
  87. package/dist/server/queries/auth/session-query.js +13 -0
  88. package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +60 -0
  89. package/dist/server/queries/multi-session/list-device-sessions-query.js +12 -0
  90. package/dist/server/queries/passkey/list-passkeys-query.d.ts +60 -0
  91. package/dist/server/queries/passkey/list-passkeys-query.js +12 -0
  92. package/dist/server/queries/settings/account-info-query.d.ts +68 -0
  93. package/dist/server/queries/settings/account-info-query.js +12 -0
  94. package/dist/server/queries/settings/list-accounts-query.d.ts +60 -0
  95. package/dist/server/queries/settings/list-accounts-query.js +12 -0
  96. package/dist/server/queries/settings/list-sessions-query.d.ts +60 -0
  97. package/dist/server/queries/settings/list-sessions-query.js +12 -0
  98. package/dist/server.d.ts +7 -0
  99. package/dist/server.js +7 -0
  100. package/package.json +24 -22
  101. package/src/components/auth/auth-provider.tsx +87 -24
  102. package/src/components/{email → auth/email}/email-changed.tsx +1 -1
  103. package/src/components/{email → auth/email}/email-verification.tsx +1 -1
  104. package/src/components/{email → auth/email}/magic-link.tsx +1 -1
  105. package/src/components/{email → auth/email}/new-device.tsx +1 -1
  106. package/src/components/{email → auth/email}/otp-email.tsx +1 -1
  107. package/src/components/{email → auth/email}/password-changed.tsx +1 -1
  108. package/src/components/{email → auth/email}/reset-password.tsx +1 -1
  109. package/src/email.ts +1 -0
  110. package/src/hooks/auth/use-authenticate.ts +12 -6
  111. package/src/hooks/auth/use-user.ts +14 -9
  112. package/src/hooks/use-auth-mutation.ts +30 -12
  113. package/src/hooks/use-auth-plugin.ts +50 -0
  114. package/src/hooks/use-auth-query.ts +11 -7
  115. package/src/index.ts +33 -32
  116. package/src/lib/auth-client.ts +33 -31
  117. package/src/lib/auth-plugin.ts +75 -0
  118. package/src/lib/auth-server.ts +30 -0
  119. package/src/mutations/auth/request-password-reset-mutation.ts +58 -0
  120. package/src/mutations/auth/reset-password-mutation.ts +60 -0
  121. package/src/mutations/auth/send-verification-email-mutation.ts +58 -0
  122. package/src/mutations/auth/sign-in-email-mutation.ts +78 -0
  123. package/src/mutations/auth/sign-in-social-mutation.ts +64 -0
  124. package/src/mutations/auth/sign-out-mutation.ts +71 -0
  125. package/src/mutations/auth/sign-up-email-mutation.ts +74 -0
  126. package/src/mutations/auth-mutation-options.ts +83 -38
  127. package/src/mutations/magic-link/sign-in-magic-link-mutation.ts +59 -0
  128. package/src/mutations/multi-session/revoke-multi-session-mutation.ts +70 -0
  129. package/src/mutations/multi-session/set-active-session-mutation.ts +98 -0
  130. package/src/mutations/passkey/add-passkey-mutation.ts +66 -0
  131. package/src/mutations/passkey/delete-passkey-mutation.ts +66 -0
  132. package/src/mutations/passkey/sign-in-passkey-mutation.ts +74 -0
  133. package/src/mutations/settings/change-email-mutation.ts +67 -0
  134. package/src/mutations/settings/change-password-mutation.ts +59 -0
  135. package/src/mutations/settings/delete-user-mutation.ts +59 -0
  136. package/src/mutations/settings/link-social-mutation.ts +59 -0
  137. package/src/mutations/settings/revoke-session-mutation.ts +69 -0
  138. package/src/mutations/settings/unlink-account-mutation.ts +67 -0
  139. package/src/mutations/settings/update-user-mutation.ts +82 -0
  140. package/src/mutations/username/is-username-available-mutation.ts +62 -0
  141. package/src/mutations/username/sign-in-username-mutation.ts +74 -0
  142. package/src/queries/auth/session-query.ts +135 -0
  143. package/src/queries/auth-query-options.ts +61 -12
  144. package/src/queries/multi-session/list-device-sessions-query.ts +177 -0
  145. package/src/queries/passkey/list-passkeys-query.ts +154 -0
  146. package/src/queries/settings/account-info-query.ts +158 -0
  147. package/src/queries/settings/list-accounts-query.ts +156 -0
  148. package/src/queries/settings/list-sessions-query.ts +154 -0
  149. package/src/server/queries/auth/session-query.ts +94 -0
  150. package/src/server/queries/multi-session/list-device-sessions-query.ts +102 -0
  151. package/src/server/queries/passkey/list-passkeys-query.ts +100 -0
  152. package/src/server/queries/settings/account-info-query.ts +101 -0
  153. package/src/server/queries/settings/list-accounts-query.ts +101 -0
  154. package/src/server/queries/settings/list-sessions-query.ts +101 -0
  155. package/src/server.ts +7 -0
  156. package/dist/core.d.ts +0 -1
  157. package/dist/core.js +0 -1
  158. package/dist/hooks/auth/use-is-username-available.d.ts +0 -20
  159. package/dist/hooks/auth/use-is-username-available.js +0 -13
  160. package/dist/hooks/auth/use-request-password-reset.d.ts +0 -21
  161. package/dist/hooks/auth/use-request-password-reset.js +0 -13
  162. package/dist/hooks/auth/use-reset-password.d.ts +0 -23
  163. package/dist/hooks/auth/use-reset-password.js +0 -13
  164. package/dist/hooks/auth/use-send-verification-email.d.ts +0 -19
  165. package/dist/hooks/auth/use-send-verification-email.js +0 -13
  166. package/dist/hooks/auth/use-session.d.ts +0 -35
  167. package/dist/hooks/auth/use-session.js +0 -16
  168. package/dist/hooks/auth/use-sign-in-email.d.ts +0 -26
  169. package/dist/hooks/auth/use-sign-in-email.js +0 -17
  170. package/dist/hooks/auth/use-sign-in-magic-link.d.ts +0 -27
  171. package/dist/hooks/auth/use-sign-in-magic-link.js +0 -13
  172. package/dist/hooks/auth/use-sign-in-passkey.d.ts +0 -21
  173. package/dist/hooks/auth/use-sign-in-passkey.js +0 -17
  174. package/dist/hooks/auth/use-sign-in-social.d.ts +0 -63
  175. package/dist/hooks/auth/use-sign-in-social.js +0 -13
  176. package/dist/hooks/auth/use-sign-in-username.d.ts +0 -25
  177. package/dist/hooks/auth/use-sign-in-username.js +0 -17
  178. package/dist/hooks/auth/use-sign-out.d.ts +0 -18
  179. package/dist/hooks/auth/use-sign-out.js +0 -16
  180. package/dist/hooks/auth/use-sign-up-email.d.ts +0 -1186
  181. package/dist/hooks/auth/use-sign-up-email.js +0 -17
  182. package/dist/hooks/settings/use-account-info.d.ts +0 -17
  183. package/dist/hooks/settings/use-account-info.js +0 -18
  184. package/dist/hooks/settings/use-add-passkey.d.ts +0 -21
  185. package/dist/hooks/settings/use-add-passkey.js +0 -17
  186. package/dist/hooks/settings/use-change-email.d.ts +0 -21
  187. package/dist/hooks/settings/use-change-email.js +0 -17
  188. package/dist/hooks/settings/use-change-password.d.ts +0 -21
  189. package/dist/hooks/settings/use-change-password.js +0 -13
  190. package/dist/hooks/settings/use-delete-passkey.d.ts +0 -19
  191. package/dist/hooks/settings/use-delete-passkey.js +0 -17
  192. package/dist/hooks/settings/use-delete-user.d.ts +0 -24
  193. package/dist/hooks/settings/use-delete-user.js +0 -13
  194. package/dist/hooks/settings/use-link-social.d.ts +0 -43
  195. package/dist/hooks/settings/use-link-social.js +0 -13
  196. package/dist/hooks/settings/use-list-accounts.d.ts +0 -22
  197. package/dist/hooks/settings/use-list-accounts.js +0 -15
  198. package/dist/hooks/settings/use-list-device-sessions.d.ts +0 -34
  199. package/dist/hooks/settings/use-list-device-sessions.js +0 -15
  200. package/dist/hooks/settings/use-list-sessions.d.ts +0 -23
  201. package/dist/hooks/settings/use-list-sessions.js +0 -15
  202. package/dist/hooks/settings/use-list-user-passkeys.d.ts +0 -14
  203. package/dist/hooks/settings/use-list-user-passkeys.js +0 -15
  204. package/dist/hooks/settings/use-revoke-multi-session.d.ts +0 -19
  205. package/dist/hooks/settings/use-revoke-multi-session.js +0 -17
  206. package/dist/hooks/settings/use-revoke-session.d.ts +0 -19
  207. package/dist/hooks/settings/use-revoke-session.js +0 -17
  208. package/dist/hooks/settings/use-set-active-session.d.ts +0 -20
  209. package/dist/hooks/settings/use-set-active-session.js +0 -20
  210. package/dist/hooks/settings/use-unlink-account.d.ts +0 -21
  211. package/dist/hooks/settings/use-unlink-account.js +0 -17
  212. package/dist/hooks/settings/use-update-user.d.ts +0 -1185
  213. package/dist/hooks/settings/use-update-user.js +0 -24
  214. package/dist/lib/auth-client.js +0 -11
  215. package/dist/lib/auth-config.d.ts +0 -43
  216. package/dist/lib/auth-context.d.ts +0 -2
  217. package/dist/lib/auth-context.js +0 -6
  218. package/dist/mutations/auth/is-username-available-options.d.ts +0 -19
  219. package/dist/mutations/auth/is-username-available-options.js +0 -7
  220. package/dist/mutations/auth/request-password-reset-options.d.ts +0 -15
  221. package/dist/mutations/auth/request-password-reset-options.js +0 -7
  222. package/dist/mutations/auth/reset-password-options.d.ts +0 -17
  223. package/dist/mutations/auth/reset-password-options.js +0 -7
  224. package/dist/mutations/auth/send-verification-email-options.d.ts +0 -15
  225. package/dist/mutations/auth/send-verification-email-options.js +0 -7
  226. package/dist/mutations/auth/sign-in-email-options.d.ts +0 -23
  227. package/dist/mutations/auth/sign-in-email-options.js +0 -11
  228. package/dist/mutations/auth/sign-in-magic-link-options.d.ts +0 -23
  229. package/dist/mutations/auth/sign-in-magic-link-options.js +0 -11
  230. package/dist/mutations/auth/sign-in-passkey-options.d.ts +0 -15
  231. package/dist/mutations/auth/sign-in-passkey-options.js +0 -11
  232. package/dist/mutations/auth/sign-in-social-options.d.ts +0 -61
  233. package/dist/mutations/auth/sign-in-social-options.js +0 -11
  234. package/dist/mutations/auth/sign-in-username-options.d.ts +0 -19
  235. package/dist/mutations/auth/sign-in-username-options.js +0 -11
  236. package/dist/mutations/auth/sign-out-options.d.ts +0 -12
  237. package/dist/mutations/auth/sign-out-options.js +0 -7
  238. package/dist/mutations/auth/sign-up-email-options.d.ts +0 -1180
  239. package/dist/mutations/auth/sign-up-email-options.js +0 -11
  240. package/dist/mutations/settings/add-passkey-options.d.ts +0 -15
  241. package/dist/mutations/settings/add-passkey-options.js +0 -11
  242. package/dist/mutations/settings/change-email-options.d.ts +0 -15
  243. package/dist/mutations/settings/change-email-options.js +0 -7
  244. package/dist/mutations/settings/change-password-options.d.ts +0 -17
  245. package/dist/mutations/settings/change-password-options.js +0 -7
  246. package/dist/mutations/settings/delete-passkey-options.d.ts +0 -13
  247. package/dist/mutations/settings/delete-passkey-options.js +0 -11
  248. package/dist/mutations/settings/delete-user-options.d.ts +0 -20
  249. package/dist/mutations/settings/delete-user-options.js +0 -7
  250. package/dist/mutations/settings/link-social-options.d.ts +0 -39
  251. package/dist/mutations/settings/link-social-options.js +0 -7
  252. package/dist/mutations/settings/revoke-multi-session-options.d.ts +0 -13
  253. package/dist/mutations/settings/revoke-multi-session-options.js +0 -11
  254. package/dist/mutations/settings/revoke-session-options.d.ts +0 -13
  255. package/dist/mutations/settings/revoke-session-options.js +0 -7
  256. package/dist/mutations/settings/set-active-session-options.d.ts +0 -13
  257. package/dist/mutations/settings/set-active-session-options.js +0 -11
  258. package/dist/mutations/settings/unlink-account-options.d.ts +0 -15
  259. package/dist/mutations/settings/unlink-account-options.js +0 -7
  260. package/dist/mutations/settings/update-user-options.d.ts +0 -1182
  261. package/dist/mutations/settings/update-user-options.js +0 -7
  262. package/dist/queries/auth/session-options.d.ts +0 -110
  263. package/dist/queries/auth/session-options.js +0 -7
  264. package/dist/queries/settings/account-info-options.d.ts +0 -32
  265. package/dist/queries/settings/account-info-options.js +0 -12
  266. package/dist/queries/settings/list-accounts-options.d.ts +0 -53
  267. package/dist/queries/settings/list-accounts-options.js +0 -12
  268. package/dist/queries/settings/list-device-sessions-options.d.ts +0 -99
  269. package/dist/queries/settings/list-device-sessions-options.js +0 -12
  270. package/dist/queries/settings/list-sessions-options.d.ts +0 -54
  271. package/dist/queries/settings/list-sessions-options.js +0 -12
  272. package/dist/queries/settings/list-user-passkeys-options.d.ts +0 -18
  273. package/dist/queries/settings/list-user-passkeys-options.js +0 -12
  274. package/src/core.ts +0 -1
  275. package/src/hooks/auth/use-is-username-available.ts +0 -31
  276. package/src/hooks/auth/use-request-password-reset.ts +0 -33
  277. package/src/hooks/auth/use-reset-password.ts +0 -31
  278. package/src/hooks/auth/use-send-verification-email.ts +0 -31
  279. package/src/hooks/auth/use-session.ts +0 -31
  280. package/src/hooks/auth/use-sign-in-email.ts +0 -41
  281. package/src/hooks/auth/use-sign-in-magic-link.ts +0 -29
  282. package/src/hooks/auth/use-sign-in-passkey.ts +0 -40
  283. package/src/hooks/auth/use-sign-in-social.ts +0 -31
  284. package/src/hooks/auth/use-sign-in-username.ts +0 -40
  285. package/src/hooks/auth/use-sign-out.ts +0 -34
  286. package/src/hooks/auth/use-sign-up-email.ts +0 -40
  287. package/src/hooks/settings/use-account-info.ts +0 -40
  288. package/src/hooks/settings/use-add-passkey.ts +0 -37
  289. package/src/hooks/settings/use-change-email.ts +0 -37
  290. package/src/hooks/settings/use-change-password.ts +0 -29
  291. package/src/hooks/settings/use-delete-passkey.ts +0 -37
  292. package/src/hooks/settings/use-delete-user.ts +0 -29
  293. package/src/hooks/settings/use-link-social.ts +0 -29
  294. package/src/hooks/settings/use-list-accounts.ts +0 -39
  295. package/src/hooks/settings/use-list-device-sessions.ts +0 -39
  296. package/src/hooks/settings/use-list-sessions.ts +0 -39
  297. package/src/hooks/settings/use-list-user-passkeys.ts +0 -39
  298. package/src/hooks/settings/use-revoke-multi-session.ts +0 -39
  299. package/src/hooks/settings/use-revoke-session.ts +0 -39
  300. package/src/hooks/settings/use-set-active-session.ts +0 -58
  301. package/src/hooks/settings/use-unlink-account.ts +0 -37
  302. package/src/hooks/settings/use-update-user.ts +0 -50
  303. package/src/lib/auth-config.ts +0 -48
  304. package/src/lib/auth-context.ts +0 -6
  305. package/src/mutations/auth/is-username-available-options.ts +0 -18
  306. package/src/mutations/auth/request-password-reset-options.ts +0 -14
  307. package/src/mutations/auth/reset-password-options.ts +0 -14
  308. package/src/mutations/auth/send-verification-email-options.ts +0 -14
  309. package/src/mutations/auth/sign-in-email-options.ts +0 -19
  310. package/src/mutations/auth/sign-in-magic-link-options.ts +0 -15
  311. package/src/mutations/auth/sign-in-passkey-options.ts +0 -15
  312. package/src/mutations/auth/sign-in-social-options.ts +0 -19
  313. package/src/mutations/auth/sign-in-username-options.ts +0 -15
  314. package/src/mutations/auth/sign-out-options.ts +0 -11
  315. package/src/mutations/auth/sign-up-email-options.ts +0 -15
  316. package/src/mutations/settings/add-passkey-options.ts +0 -15
  317. package/src/mutations/settings/change-email-options.ts +0 -11
  318. package/src/mutations/settings/change-password-options.ts +0 -14
  319. package/src/mutations/settings/delete-passkey-options.ts +0 -15
  320. package/src/mutations/settings/delete-user-options.ts +0 -11
  321. package/src/mutations/settings/link-social-options.ts +0 -11
  322. package/src/mutations/settings/revoke-multi-session-options.ts +0 -15
  323. package/src/mutations/settings/revoke-session-options.ts +0 -14
  324. package/src/mutations/settings/set-active-session-options.ts +0 -15
  325. package/src/mutations/settings/unlink-account-options.ts +0 -14
  326. package/src/mutations/settings/update-user-options.ts +0 -15
  327. package/src/queries/auth/session-options.ts +0 -18
  328. package/src/queries/settings/account-info-options.ts +0 -25
  329. package/src/queries/settings/list-accounts-options.ts +0 -26
  330. package/src/queries/settings/list-device-sessions-options.ts +0 -24
  331. package/src/queries/settings/list-sessions-options.ts +0 -23
  332. package/src/queries/settings/list-user-passkeys-options.ts +0 -23
  333. /package/dist/components/{email → auth/email}/email-changed.d.ts +0 -0
  334. /package/dist/components/{email → auth/email}/email-localization.d.ts +0 -0
  335. /package/dist/components/{email → auth/email}/email-styles.d.ts +0 -0
  336. /package/dist/components/{email → auth/email}/email-verification.d.ts +0 -0
  337. /package/dist/components/{email → auth/email}/index.d.ts +0 -0
  338. /package/dist/components/{email → auth/email}/index.js +0 -0
  339. /package/dist/components/{email → auth/email}/magic-link.d.ts +0 -0
  340. /package/dist/components/{email → auth/email}/new-device.d.ts +0 -0
  341. /package/dist/components/{email → auth/email}/otp-email.d.ts +0 -0
  342. /package/dist/components/{email → auth/email}/password-changed.d.ts +0 -0
  343. /package/dist/components/{email → auth/email}/reset-password.d.ts +0 -0
  344. /package/src/components/{email → auth/email}/email-localization.tsx +0 -0
  345. /package/src/components/{email → auth/email}/email-styles.tsx +0 -0
  346. /package/src/components/{email → auth/email}/index.ts +0 -0
@@ -0,0 +1,154 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions,
6
+ skipToken,
7
+ useQuery
8
+ } from "@tanstack/react-query"
9
+ import type { BetterFetchError } from "better-auth/react"
10
+
11
+ import type { AuthClient, InferData } from "../../lib/auth-client"
12
+ import { useSession } from "../auth/session-query"
13
+
14
+ export type ListSessionsData<TAuthClient extends AuthClient> = InferData<
15
+ TAuthClient["listSessions"]
16
+ >
17
+
18
+ export type ListSessionsParams<TAuthClient extends AuthClient> = Parameters<
19
+ TAuthClient["listSessions"]
20
+ >[0]
21
+
22
+ export type ListSession<TAuthClient extends AuthClient = AuthClient> =
23
+ NonNullable<ListSessionsData<TAuthClient>>[number]
24
+
25
+ export type ListSessionsOptions<TAuthClient extends AuthClient> = Omit<
26
+ ReturnType<typeof listSessionsOptions<TAuthClient>>,
27
+ "queryKey" | "queryFn"
28
+ >
29
+
30
+ /**
31
+ * Query options factory for the current user's active sessions.
32
+ *
33
+ * @param authClient - The Better Auth client.
34
+ * @param userId - The current signed-in user's ID. Used for cache partitioning.
35
+ * @param params - Parameters forwarded to `authClient.listSessions`.
36
+ */
37
+ export function listSessionsOptions<TAuthClient extends AuthClient>(
38
+ authClient: TAuthClient,
39
+ userId: string | undefined,
40
+ params?: ListSessionsParams<TAuthClient>
41
+ ) {
42
+ type TData = ListSessionsData<TAuthClient>
43
+ const queryKey = authQueryKeys.listSessions(userId, params?.query)
44
+
45
+ const options = queryOptions<TData, BetterFetchError, TData, typeof queryKey>(
46
+ {
47
+ queryKey,
48
+ queryFn: ({ signal }) =>
49
+ authClient.listSessions({
50
+ ...params,
51
+ fetchOptions: { ...params?.fetchOptions, signal, throw: true }
52
+ }) as Promise<TData>
53
+ }
54
+ )
55
+
56
+ return options as typeof options & {
57
+ queryKey: DataTag<typeof queryKey, TData, BetterFetchError>
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Get the current user's active sessions from the query cache, calling
63
+ * `fetchListSessions` under the hood if no cached entry exists. Resolves
64
+ * with the session list, making it ideal for loaders or `beforeLoad` guards.
65
+ *
66
+ * @param queryClient - The React Query client.
67
+ * @param authClient - The Better Auth client.
68
+ * @param userId - The signed-in user's ID, used for cache partitioning.
69
+ * @param params - Parameters forwarded to `authClient.listSessions`.
70
+ */
71
+ export const ensureListSessions = <TAuthClient extends AuthClient>(
72
+ queryClient: QueryClient,
73
+ authClient: TAuthClient,
74
+ userId: string,
75
+ params?: ListSessionsParams<TAuthClient>
76
+ ) =>
77
+ queryClient.ensureQueryData(listSessionsOptions(authClient, userId, params))
78
+
79
+ /**
80
+ * Prefetch the current user's active sessions into the query cache. Behaves
81
+ * like `fetchListSessions`, but does not throw on error and does not return
82
+ * the data — use this to warm the cache without blocking navigation.
83
+ *
84
+ * @param queryClient - The React Query client.
85
+ * @param authClient - The Better Auth client.
86
+ * @param userId - The signed-in user's ID, used for cache partitioning.
87
+ * @param params - Parameters forwarded to `authClient.listSessions`.
88
+ */
89
+ export const prefetchListSessions = <TAuthClient extends AuthClient>(
90
+ queryClient: QueryClient,
91
+ authClient: TAuthClient,
92
+ userId: string,
93
+ params?: ListSessionsParams<TAuthClient>
94
+ ) => queryClient.prefetchQuery(listSessionsOptions(authClient, userId, params))
95
+
96
+ /**
97
+ * Fetch and cache the current user's active sessions, resolving with the
98
+ * data or throwing on error. If a cached entry exists and is neither
99
+ * invalidated nor older than `staleTime`, the cached value is returned
100
+ * without a network call; otherwise the latest data is fetched.
101
+ *
102
+ * @param queryClient - The React Query client.
103
+ * @param authClient - The Better Auth client.
104
+ * @param userId - The signed-in user's ID, used for cache partitioning.
105
+ * @param params - Parameters forwarded to `authClient.listSessions`.
106
+ */
107
+ export const fetchListSessions = <TAuthClient extends AuthClient>(
108
+ queryClient: QueryClient,
109
+ authClient: TAuthClient,
110
+ userId: string,
111
+ params?: ListSessionsParams<TAuthClient>
112
+ ) => queryClient.fetchQuery(listSessionsOptions(authClient, userId, params))
113
+
114
+ export type UseListSessionsOptions<TAuthClient extends AuthClient> =
115
+ ListSessionsOptions<TAuthClient> & ListSessionsParams<TAuthClient>
116
+
117
+ /**
118
+ * Subscribe to the current user's active sessions via TanStack Query.
119
+ *
120
+ * Shares a query key with the server-side `listSessionsOptions`, so
121
+ * SSR-hydrated data is reused from the cache without an immediate refetch.
122
+ * The query is gated on a signed-in user; while the session is loading or
123
+ * absent, the underlying `queryFn` is replaced with `skipToken`.
124
+ *
125
+ * @param authClient - The Better Auth client.
126
+ * @param options - `listSessions` params (`query`, `fetchOptions`) merged
127
+ * with `useQuery` options (e.g. `enabled`, `staleTime`, `select`).
128
+ * @param queryClient - Optional custom `QueryClient`. Defaults to the client
129
+ * from the nearest `QueryClientProvider`.
130
+ */
131
+ export function useListSessions<TAuthClient extends AuthClient>(
132
+ authClient: TAuthClient,
133
+ options: UseListSessionsOptions<TAuthClient> = {},
134
+ queryClient?: QueryClient
135
+ ) {
136
+ const { data: session } = useSession(authClient, undefined, queryClient)
137
+ const userId = session?.user.id
138
+
139
+ const { query, fetchOptions, ...queryOptions } = options
140
+
141
+ const baseOptions = listSessionsOptions(authClient, userId, {
142
+ query,
143
+ fetchOptions
144
+ })
145
+
146
+ return useQuery(
147
+ {
148
+ ...queryOptions,
149
+ ...baseOptions,
150
+ queryFn: userId ? baseOptions.queryFn : skipToken
151
+ },
152
+ queryClient
153
+ )
154
+ }
@@ -0,0 +1,94 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions
6
+ } from "@tanstack/react-query"
7
+ import type { APIError } from "better-auth"
8
+
9
+ import type { AuthServer } from "../../../lib/auth-server"
10
+
11
+ export type SessionData<TAuth extends AuthServer = AuthServer> = Awaited<
12
+ ReturnType<TAuth["api"]["getSession"]>
13
+ >
14
+
15
+ export type Session<TAuth extends AuthServer = AuthServer> = NonNullable<
16
+ SessionData<TAuth>
17
+ >
18
+
19
+ export type SessionParams<TAuth extends AuthServer> = Parameters<
20
+ TAuth["api"]["getSession"]
21
+ >[0]
22
+
23
+ /**
24
+ * Query options factory for the current session on the server.
25
+ *
26
+ * Uses the same query key as the client-side `sessionOptions` so that data
27
+ * fetched during SSR hydrates seamlessly into the client's React Query cache.
28
+ *
29
+ * @param auth - The Better Auth server instance.
30
+ * @param params - Parameters forwarded to `auth.api.getSession` (typically
31
+ * includes request `headers` for cookie-based session resolution).
32
+ */
33
+ export function sessionOptions<TAuth extends AuthServer>(
34
+ auth: TAuth,
35
+ params: SessionParams<TAuth>
36
+ ) {
37
+ type TData = SessionData<TAuth>
38
+ const queryKey = authQueryKeys.session
39
+
40
+ const options = queryOptions<TData, APIError, TData, typeof queryKey>({
41
+ queryKey,
42
+ queryFn: () => auth.api.getSession(params) as Promise<TData>
43
+ })
44
+
45
+ return options as typeof options & {
46
+ queryKey: DataTag<typeof queryKey, TData, APIError>
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Get the current session from the query cache, calling `fetchSession` under
52
+ * the hood if no cached entry exists. Resolves with the session data, making
53
+ * it suitable for reading the value directly in a server component.
54
+ *
55
+ * @param queryClient - The React Query client used for SSR hydration.
56
+ * @param auth - The Better Auth server instance.
57
+ * @param params - Parameters forwarded to `auth.api.getSession`.
58
+ */
59
+ export const ensureSession = <TAuth extends AuthServer>(
60
+ queryClient: QueryClient,
61
+ auth: TAuth,
62
+ params: SessionParams<TAuth>
63
+ ) => queryClient.ensureQueryData(sessionOptions(auth, params))
64
+
65
+ /**
66
+ * Prefetch the current session into the query cache. Behaves like
67
+ * `fetchSession`, but does not throw on error and does not return the data —
68
+ * use this when you only need the value to be available after hydration.
69
+ *
70
+ * @param queryClient - The React Query client used for SSR hydration.
71
+ * @param auth - The Better Auth server instance.
72
+ * @param params - Parameters forwarded to `auth.api.getSession`.
73
+ */
74
+ export const prefetchSession = <TAuth extends AuthServer>(
75
+ queryClient: QueryClient,
76
+ auth: TAuth,
77
+ params: SessionParams<TAuth>
78
+ ) => queryClient.prefetchQuery(sessionOptions(auth, params))
79
+
80
+ /**
81
+ * Fetch and cache the current session, resolving with the data or throwing
82
+ * on error. If a cached entry exists and is neither invalidated nor older
83
+ * than `staleTime`, the cached value is returned without a network call;
84
+ * otherwise the latest data is fetched.
85
+ *
86
+ * @param queryClient - The React Query client used for SSR hydration.
87
+ * @param auth - The Better Auth server instance.
88
+ * @param params - Parameters forwarded to `auth.api.getSession`.
89
+ */
90
+ export const fetchSession = <TAuth extends AuthServer>(
91
+ queryClient: QueryClient,
92
+ auth: TAuth,
93
+ params: SessionParams<TAuth>
94
+ ) => queryClient.fetchQuery(sessionOptions(auth, params))
@@ -0,0 +1,102 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions
6
+ } from "@tanstack/react-query"
7
+ import type { APIError } from "better-auth"
8
+
9
+ import type { MultiSessionAuthServer } from "../../../lib/auth-server"
10
+
11
+ export type ListDeviceSessionsData<TAuth extends MultiSessionAuthServer> =
12
+ Awaited<ReturnType<TAuth["api"]["listDeviceSessions"]>>
13
+
14
+ export type ListDeviceSession<
15
+ TAuth extends MultiSessionAuthServer = MultiSessionAuthServer
16
+ > = NonNullable<ListDeviceSessionsData<TAuth>>[number]
17
+
18
+ export type ListDeviceSessionsParams<TAuth extends MultiSessionAuthServer> =
19
+ Parameters<TAuth["api"]["listDeviceSessions"]>[0]
20
+
21
+ /**
22
+ * Query options factory for the current user's device sessions.
23
+ *
24
+ * @param auth - The Better Auth server instance with the multi-session plugin.
25
+ * @param userId - The signed-in user's ID. Used for cache partitioning so
26
+ * the key matches the client-side `listDeviceSessionsOptions` for SSR hydration.
27
+ * @param params - Parameters forwarded to `auth.api.listDeviceSessions`.
28
+ */
29
+ export function listDeviceSessionsOptions<TAuth extends MultiSessionAuthServer>(
30
+ auth: TAuth,
31
+ userId: string,
32
+ params: ListDeviceSessionsParams<TAuth>
33
+ ) {
34
+ type TData = ListDeviceSessionsData<TAuth>
35
+ const queryKey = authQueryKeys.listDeviceSessions(userId, params?.query)
36
+
37
+ const options = queryOptions<TData, APIError, TData, typeof queryKey>({
38
+ queryKey,
39
+ queryFn: () => auth.api.listDeviceSessions(params) as Promise<TData>
40
+ })
41
+
42
+ return options as typeof options & {
43
+ queryKey: DataTag<typeof queryKey, TData, APIError>
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Get the current user's device sessions from the query cache, calling
49
+ * `fetchListDeviceSessions` under the hood if no cached entry exists.
50
+ * Resolves with the device session list, making it suitable for reading
51
+ * directly in a server component.
52
+ *
53
+ * @param queryClient - The React Query client used for SSR hydration.
54
+ * @param auth - The Better Auth server instance with the multi-session plugin.
55
+ * @param userId - The signed-in user's ID, used for cache partitioning.
56
+ * @param params - Parameters forwarded to `auth.api.listDeviceSessions`.
57
+ */
58
+ export const ensureListDeviceSessions = <TAuth extends MultiSessionAuthServer>(
59
+ queryClient: QueryClient,
60
+ auth: TAuth,
61
+ userId: string,
62
+ params: ListDeviceSessionsParams<TAuth>
63
+ ) =>
64
+ queryClient.ensureQueryData(listDeviceSessionsOptions(auth, userId, params))
65
+
66
+ /**
67
+ * Prefetch the current user's device sessions into the query cache. Behaves
68
+ * like `fetchListDeviceSessions`, but does not throw on error and does not
69
+ * return the data — use this when you only need the value to be available
70
+ * after hydration.
71
+ *
72
+ * @param queryClient - The React Query client used for SSR hydration.
73
+ * @param auth - The Better Auth server instance with the multi-session plugin.
74
+ * @param userId - The signed-in user's ID, used for cache partitioning.
75
+ * @param params - Parameters forwarded to `auth.api.listDeviceSessions`.
76
+ */
77
+ export const prefetchListDeviceSessions = <
78
+ TAuth extends MultiSessionAuthServer
79
+ >(
80
+ queryClient: QueryClient,
81
+ auth: TAuth,
82
+ userId: string,
83
+ params: ListDeviceSessionsParams<TAuth>
84
+ ) => queryClient.prefetchQuery(listDeviceSessionsOptions(auth, userId, params))
85
+
86
+ /**
87
+ * Fetch and cache the current user's device sessions, resolving with the
88
+ * data or throwing on error. If a cached entry exists and is neither
89
+ * invalidated nor older than `staleTime`, the cached value is returned
90
+ * without a network call; otherwise the latest data is fetched.
91
+ *
92
+ * @param queryClient - The React Query client used for SSR hydration.
93
+ * @param auth - The Better Auth server instance with the multi-session plugin.
94
+ * @param userId - The signed-in user's ID, used for cache partitioning.
95
+ * @param params - Parameters forwarded to `auth.api.listDeviceSessions`.
96
+ */
97
+ export const fetchListDeviceSessions = <TAuth extends MultiSessionAuthServer>(
98
+ queryClient: QueryClient,
99
+ auth: TAuth,
100
+ userId: string,
101
+ params: ListDeviceSessionsParams<TAuth>
102
+ ) => queryClient.fetchQuery(listDeviceSessionsOptions(auth, userId, params))
@@ -0,0 +1,100 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions
6
+ } from "@tanstack/react-query"
7
+ import type { APIError } from "better-auth"
8
+
9
+ import type { PasskeyAuthServer } from "../../../lib/auth-server"
10
+
11
+ export type ListPasskeysData<TAuth extends PasskeyAuthServer> = Awaited<
12
+ ReturnType<TAuth["api"]["listPasskeys"]>
13
+ >
14
+
15
+ export type ListPasskeysParams<TAuth extends PasskeyAuthServer> = Parameters<
16
+ TAuth["api"]["listPasskeys"]
17
+ >[0]
18
+
19
+ export type ListPasskey<TAuth extends PasskeyAuthServer = PasskeyAuthServer> =
20
+ NonNullable<ListPasskeysData<TAuth>>[number]
21
+
22
+ /**
23
+ * Query options factory for the current user's passkeys.
24
+ *
25
+ * @param auth - The Better Auth server instance with the passkey plugin.
26
+ * @param userId - The signed-in user's ID. Used for cache partitioning so
27
+ * the key matches the client-side `listPasskeysOptions` for SSR hydration.
28
+ * @param params - Parameters forwarded to `auth.api.listPasskeys`.
29
+ */
30
+ export function listPasskeysOptions<TAuth extends PasskeyAuthServer>(
31
+ auth: TAuth,
32
+ userId: string,
33
+ params: ListPasskeysParams<TAuth>
34
+ ) {
35
+ type TData = ListPasskeysData<TAuth>
36
+ const queryKey = authQueryKeys.listPasskeys(userId, params?.query)
37
+
38
+ const options = queryOptions<TData, APIError, TData, typeof queryKey>({
39
+ queryKey,
40
+ queryFn: () => auth.api.listPasskeys(params) as Promise<TData>
41
+ })
42
+
43
+ return options as typeof options & {
44
+ queryKey: DataTag<typeof queryKey, TData, APIError>
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Get the current user's passkeys from the query cache, calling
50
+ * `fetchListPasskeys` under the hood if no cached entry exists. Resolves
51
+ * with the passkey list, making it suitable for reading directly in a server
52
+ * component.
53
+ *
54
+ * @param queryClient - The React Query client used for SSR hydration.
55
+ * @param auth - The Better Auth server instance with the passkey plugin.
56
+ * @param userId - The signed-in user's ID, used for cache partitioning.
57
+ * @param params - Parameters forwarded to `auth.api.listPasskeys`.
58
+ */
59
+ export const ensureListPasskeys = <TAuth extends PasskeyAuthServer>(
60
+ queryClient: QueryClient,
61
+ auth: TAuth,
62
+ userId: string,
63
+ params: ListPasskeysParams<TAuth>
64
+ ) => queryClient.ensureQueryData(listPasskeysOptions(auth, userId, params))
65
+
66
+ /**
67
+ * Prefetch the current user's passkeys into the query cache. Behaves like
68
+ * `fetchListPasskeys`, but does not throw on error and does not return
69
+ * the data — use this when you only need the value to be available after
70
+ * hydration.
71
+ *
72
+ * @param queryClient - The React Query client used for SSR hydration.
73
+ * @param auth - The Better Auth server instance with the passkey plugin.
74
+ * @param userId - The signed-in user's ID, used for cache partitioning.
75
+ * @param params - Parameters forwarded to `auth.api.listPasskeys`.
76
+ */
77
+ export const prefetchListPasskeys = <TAuth extends PasskeyAuthServer>(
78
+ queryClient: QueryClient,
79
+ auth: TAuth,
80
+ userId: string,
81
+ params: ListPasskeysParams<TAuth>
82
+ ) => queryClient.prefetchQuery(listPasskeysOptions(auth, userId, params))
83
+
84
+ /**
85
+ * Fetch and cache the current user's passkeys, resolving with the data or
86
+ * throwing on error. If a cached entry exists and is neither invalidated
87
+ * nor older than `staleTime`, the cached value is returned without a
88
+ * network call; otherwise the latest data is fetched.
89
+ *
90
+ * @param queryClient - The React Query client used for SSR hydration.
91
+ * @param auth - The Better Auth server instance with the passkey plugin.
92
+ * @param userId - The signed-in user's ID, used for cache partitioning.
93
+ * @param params - Parameters forwarded to `auth.api.listPasskeys`.
94
+ */
95
+ export const fetchListPasskeys = <TAuth extends PasskeyAuthServer>(
96
+ queryClient: QueryClient,
97
+ auth: TAuth,
98
+ userId: string,
99
+ params: ListPasskeysParams<TAuth>
100
+ ) => queryClient.fetchQuery(listPasskeysOptions(auth, userId, params))
@@ -0,0 +1,101 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions
6
+ } from "@tanstack/react-query"
7
+ import type { APIError } from "better-auth"
8
+
9
+ import type { AuthServer } from "../../../lib/auth-server"
10
+
11
+ export type AccountInfoData<TAuth extends AuthServer = AuthServer> = Awaited<
12
+ ReturnType<TAuth["api"]["accountInfo"]>
13
+ >
14
+
15
+ export type AccountInfoParams<TAuth extends AuthServer> = Parameters<
16
+ TAuth["api"]["accountInfo"]
17
+ >[0]
18
+
19
+ export type AccountInfo<TAuth extends AuthServer = AuthServer> = NonNullable<
20
+ AccountInfoData<TAuth>
21
+ >
22
+
23
+ /**
24
+ * Query options factory for provider-specific account info.
25
+ *
26
+ * @param auth - The Better Auth server instance.
27
+ * @param userId - The signed-in user's ID. Used for cache partitioning so
28
+ * the key matches the client-side `accountInfoOptions` for SSR hydration.
29
+ * @param params - Parameters forwarded to `auth.api.accountInfo`.
30
+ */
31
+ export function accountInfoOptions<TAuth extends AuthServer>(
32
+ auth: TAuth,
33
+ userId: string,
34
+ params: AccountInfoParams<TAuth>
35
+ ) {
36
+ type TData = AccountInfoData<TAuth>
37
+ const queryKey = authQueryKeys.accountInfo(userId, params?.query)
38
+
39
+ const options = queryOptions<TData, APIError, TData, typeof queryKey>({
40
+ queryKey,
41
+ queryFn: () => auth.api.accountInfo(params) as Promise<TData>
42
+ })
43
+
44
+ return options as typeof options & {
45
+ queryKey: DataTag<typeof queryKey, TData, APIError>
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Get the current user's provider-specific account info from the query
51
+ * cache, calling `fetchAccountInfo` under the hood if no cached entry
52
+ * exists. Resolves with the data, making it suitable for reading directly
53
+ * in a server component.
54
+ *
55
+ * @param queryClient - The React Query client used for SSR hydration.
56
+ * @param auth - The Better Auth server instance.
57
+ * @param userId - The signed-in user's ID, used for cache partitioning.
58
+ * @param params - Parameters forwarded to `auth.api.accountInfo`.
59
+ */
60
+ export const ensureAccountInfo = <TAuth extends AuthServer>(
61
+ queryClient: QueryClient,
62
+ auth: TAuth,
63
+ userId: string,
64
+ params: AccountInfoParams<TAuth>
65
+ ) => queryClient.ensureQueryData(accountInfoOptions(auth, userId, params))
66
+
67
+ /**
68
+ * Prefetch the current user's provider-specific account info into the query
69
+ * cache. Behaves like `fetchAccountInfo`, but does not throw on error and
70
+ * does not return the data — use this when you only need the value to be
71
+ * available after hydration.
72
+ *
73
+ * @param queryClient - The React Query client used for SSR hydration.
74
+ * @param auth - The Better Auth server instance.
75
+ * @param userId - The signed-in user's ID, used for cache partitioning.
76
+ * @param params - Parameters forwarded to `auth.api.accountInfo`.
77
+ */
78
+ export const prefetchAccountInfo = <TAuth extends AuthServer>(
79
+ queryClient: QueryClient,
80
+ auth: TAuth,
81
+ userId: string,
82
+ params: AccountInfoParams<TAuth>
83
+ ) => queryClient.prefetchQuery(accountInfoOptions(auth, userId, params))
84
+
85
+ /**
86
+ * Fetch and cache the current user's provider-specific account info,
87
+ * resolving with the data or throwing on error. If a cached entry exists
88
+ * and is neither invalidated nor older than `staleTime`, the cached value
89
+ * is returned without a network call; otherwise the latest data is fetched.
90
+ *
91
+ * @param queryClient - The React Query client used for SSR hydration.
92
+ * @param auth - The Better Auth server instance.
93
+ * @param userId - The signed-in user's ID, used for cache partitioning.
94
+ * @param params - Parameters forwarded to `auth.api.accountInfo`.
95
+ */
96
+ export const fetchAccountInfo = <TAuth extends AuthServer>(
97
+ queryClient: QueryClient,
98
+ auth: TAuth,
99
+ userId: string,
100
+ params: AccountInfoParams<TAuth>
101
+ ) => queryClient.fetchQuery(accountInfoOptions(auth, userId, params))
@@ -0,0 +1,101 @@
1
+ import { authQueryKeys } from "@better-auth-ui/core"
2
+ import {
3
+ type DataTag,
4
+ type QueryClient,
5
+ queryOptions
6
+ } from "@tanstack/react-query"
7
+ import type { APIError } from "better-auth"
8
+
9
+ import type { AuthServer } from "../../../lib/auth-server"
10
+
11
+ export type ListAccountsData<TAuth extends AuthServer = AuthServer> = Awaited<
12
+ ReturnType<TAuth["api"]["listUserAccounts"]>
13
+ >
14
+
15
+ export type ListAccountsParams<TAuth extends AuthServer> = Parameters<
16
+ TAuth["api"]["listUserAccounts"]
17
+ >[0]
18
+
19
+ export type ListAccount<TAuth extends AuthServer = AuthServer> = NonNullable<
20
+ ListAccountsData<TAuth>
21
+ >[number]
22
+
23
+ /**
24
+ * Query options factory for the current user's linked social accounts.
25
+ *
26
+ * @param auth - The Better Auth server instance.
27
+ * @param userId - The signed-in user's ID. Used for cache partitioning so
28
+ * the key matches the client-side `listAccountsOptions` for SSR hydration.
29
+ * @param params - Parameters forwarded to `auth.api.listUserAccounts`.
30
+ */
31
+ export function listAccountsOptions<TAuth extends AuthServer>(
32
+ auth: TAuth,
33
+ userId: string,
34
+ params: ListAccountsParams<TAuth>
35
+ ) {
36
+ type TData = ListAccountsData<TAuth>
37
+ const queryKey = authQueryKeys.listAccounts(userId, params?.query)
38
+
39
+ const options = queryOptions<TData, APIError, TData, typeof queryKey>({
40
+ queryKey,
41
+ queryFn: () => auth.api.listUserAccounts(params) as Promise<TData>
42
+ })
43
+
44
+ return options as typeof options & {
45
+ queryKey: DataTag<typeof queryKey, TData, APIError>
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Get the current user's linked social accounts from the query cache,
51
+ * calling `fetchListAccounts` under the hood if no cached entry exists.
52
+ * Resolves with the account list, making it suitable for reading directly
53
+ * in a server component.
54
+ *
55
+ * @param queryClient - The React Query client used for SSR hydration.
56
+ * @param auth - The Better Auth server instance.
57
+ * @param userId - The signed-in user's ID, used for cache partitioning.
58
+ * @param params - Parameters forwarded to `auth.api.listUserAccounts`.
59
+ */
60
+ export const ensureListAccounts = <TAuth extends AuthServer>(
61
+ queryClient: QueryClient,
62
+ auth: TAuth,
63
+ userId: string,
64
+ params: ListAccountsParams<TAuth>
65
+ ) => queryClient.ensureQueryData(listAccountsOptions(auth, userId, params))
66
+
67
+ /**
68
+ * Prefetch the current user's linked social accounts into the query cache.
69
+ * Behaves like `fetchListAccounts`, but does not throw on error and does
70
+ * not return the data — use this when you only need the value to be
71
+ * available after hydration.
72
+ *
73
+ * @param queryClient - The React Query client used for SSR hydration.
74
+ * @param auth - The Better Auth server instance.
75
+ * @param userId - The signed-in user's ID, used for cache partitioning.
76
+ * @param params - Parameters forwarded to `auth.api.listUserAccounts`.
77
+ */
78
+ export const prefetchListAccounts = <TAuth extends AuthServer>(
79
+ queryClient: QueryClient,
80
+ auth: TAuth,
81
+ userId: string,
82
+ params: ListAccountsParams<TAuth>
83
+ ) => queryClient.prefetchQuery(listAccountsOptions(auth, userId, params))
84
+
85
+ /**
86
+ * Fetch and cache the current user's linked social accounts, resolving
87
+ * with the data or throwing on error. If a cached entry exists and is
88
+ * neither invalidated nor older than `staleTime`, the cached value is
89
+ * returned without a network call; otherwise the latest data is fetched.
90
+ *
91
+ * @param queryClient - The React Query client used for SSR hydration.
92
+ * @param auth - The Better Auth server instance.
93
+ * @param userId - The signed-in user's ID, used for cache partitioning.
94
+ * @param params - Parameters forwarded to `auth.api.listUserAccounts`.
95
+ */
96
+ export const fetchListAccounts = <TAuth extends AuthServer>(
97
+ queryClient: QueryClient,
98
+ auth: TAuth,
99
+ userId: string,
100
+ params: ListAccountsParams<TAuth>
101
+ ) => queryClient.fetchQuery(listAccountsOptions(auth, userId, params))