@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.
- package/dist/components/auth/auth-provider.d.ts +23 -8
- package/dist/components/auth/auth-provider.js +32 -17
- package/dist/components/{email → auth/email}/email-changed.js +2 -2
- package/dist/components/{email → auth/email}/email-localization.js +1 -1
- package/dist/components/{email → auth/email}/email-styles.js +1 -1
- package/dist/components/{email → auth/email}/email-verification.js +2 -2
- package/dist/components/{email → auth/email}/magic-link.js +2 -2
- package/dist/components/{email → auth/email}/new-device.js +2 -2
- package/dist/components/{email → auth/email}/otp-email.js +2 -2
- package/dist/components/{email → auth/email}/password-changed.js +2 -2
- package/dist/components/{email → auth/email}/reset-password.js +2 -2
- package/dist/email.d.ts +1 -0
- package/dist/email.js +11 -0
- package/dist/hooks/auth/use-authenticate.d.ts +5 -28
- package/dist/hooks/auth/use-authenticate.js +12 -12
- package/dist/hooks/auth/use-user.d.ts +19 -314
- package/dist/hooks/auth/use-user.js +5 -5
- package/dist/hooks/use-auth-mutation.d.ts +12 -7
- package/dist/hooks/use-auth-plugin.d.ts +31 -0
- package/dist/hooks/use-auth-plugin.js +10 -0
- package/dist/hooks/use-auth-query.d.ts +3 -3
- package/dist/index.d.ts +33 -32
- package/dist/index.js +74 -83
- package/dist/lib/auth-client.d.ts +23 -3687
- package/dist/lib/auth-plugin.d.ts +59 -0
- package/dist/lib/auth-server.d.ts +16 -0
- package/dist/mutations/auth/request-password-reset-mutation.d.ts +26 -0
- package/dist/mutations/auth/request-password-reset-mutation.js +24 -0
- package/dist/mutations/auth/reset-password-mutation.d.ts +25 -0
- package/dist/mutations/auth/reset-password-mutation.js +24 -0
- package/dist/mutations/auth/send-verification-email-mutation.d.ts +24 -0
- package/dist/mutations/auth/send-verification-email-mutation.js +24 -0
- package/dist/mutations/auth/sign-in-email-mutation.d.ts +71 -0
- package/dist/mutations/auth/sign-in-email-mutation.js +29 -0
- package/dist/mutations/auth/sign-in-social-mutation.d.ts +77 -0
- package/dist/mutations/auth/sign-in-social-mutation.js +24 -0
- package/dist/mutations/auth/sign-out-mutation.d.ts +25 -0
- package/dist/mutations/auth/sign-out-mutation.js +28 -0
- package/dist/mutations/auth/sign-up-email-mutation.d.ts +105 -0
- package/dist/mutations/auth/sign-up-email-mutation.js +29 -0
- package/dist/mutations/auth-mutation-options.d.ts +37 -20
- package/dist/mutations/auth-mutation-options.js +2 -2
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.d.ts +24 -0
- package/dist/mutations/magic-link/sign-in-magic-link-mutation.js +24 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.d.ts +25 -0
- package/dist/mutations/multi-session/revoke-multi-session-mutation.js +29 -0
- package/dist/mutations/multi-session/set-active-session-mutation.d.ts +62 -0
- package/dist/mutations/multi-session/set-active-session-mutation.js +31 -0
- package/dist/mutations/passkey/add-passkey-mutation.d.ts +71 -0
- package/dist/mutations/passkey/add-passkey-mutation.js +29 -0
- package/dist/mutations/passkey/delete-passkey-mutation.d.ts +25 -0
- package/dist/mutations/passkey/delete-passkey-mutation.js +29 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.d.ts +105 -0
- package/dist/mutations/passkey/sign-in-passkey-mutation.js +29 -0
- package/dist/mutations/settings/change-email-mutation.d.ts +25 -0
- package/dist/mutations/settings/change-email-mutation.js +29 -0
- package/dist/mutations/settings/change-password-mutation.d.ts +78 -0
- package/dist/mutations/settings/change-password-mutation.js +24 -0
- package/dist/mutations/settings/delete-user-mutation.d.ts +26 -0
- package/dist/mutations/settings/delete-user-mutation.js +24 -0
- package/dist/mutations/settings/link-social-mutation.d.ts +26 -0
- package/dist/mutations/settings/link-social-mutation.js +24 -0
- package/dist/mutations/settings/revoke-session-mutation.d.ts +25 -0
- package/dist/mutations/settings/revoke-session-mutation.js +29 -0
- package/dist/mutations/settings/unlink-account-mutation.d.ts +25 -0
- package/dist/mutations/settings/unlink-account-mutation.js +29 -0
- package/dist/mutations/settings/update-user-mutation.d.ts +25 -0
- package/dist/mutations/settings/update-user-mutation.js +35 -0
- package/dist/mutations/username/is-username-available-mutation.d.ts +27 -0
- package/dist/mutations/username/is-username-available-mutation.js +24 -0
- package/dist/mutations/username/sign-in-username-mutation.d.ts +75 -0
- package/dist/mutations/username/sign-in-username-mutation.js +29 -0
- package/dist/queries/auth/session-query.d.ts +71 -0
- package/dist/queries/auth/session-query.js +30 -0
- package/dist/queries/auth-query-options.d.ts +26 -15
- package/dist/queries/multi-session/list-device-sessions-query.d.ts +76 -0
- package/dist/queries/multi-session/list-device-sessions-query.js +31 -0
- package/dist/queries/passkey/list-passkeys-query.d.ts +74 -0
- package/dist/queries/passkey/list-passkeys-query.js +31 -0
- package/dist/queries/settings/account-info-query.d.ts +85 -0
- package/dist/queries/settings/account-info-query.js +31 -0
- package/dist/queries/settings/list-accounts-query.d.ts +76 -0
- package/dist/queries/settings/list-accounts-query.js +31 -0
- package/dist/queries/settings/list-sessions-query.d.ts +74 -0
- package/dist/queries/settings/list-sessions-query.js +31 -0
- package/dist/server/queries/auth/session-query.d.ts +57 -0
- package/dist/server/queries/auth/session-query.js +13 -0
- package/dist/server/queries/multi-session/list-device-sessions-query.d.ts +60 -0
- package/dist/server/queries/multi-session/list-device-sessions-query.js +12 -0
- package/dist/server/queries/passkey/list-passkeys-query.d.ts +60 -0
- package/dist/server/queries/passkey/list-passkeys-query.js +12 -0
- package/dist/server/queries/settings/account-info-query.d.ts +68 -0
- package/dist/server/queries/settings/account-info-query.js +12 -0
- package/dist/server/queries/settings/list-accounts-query.d.ts +60 -0
- package/dist/server/queries/settings/list-accounts-query.js +12 -0
- package/dist/server/queries/settings/list-sessions-query.d.ts +60 -0
- package/dist/server/queries/settings/list-sessions-query.js +12 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +7 -0
- package/package.json +24 -22
- package/src/components/auth/auth-provider.tsx +87 -24
- package/src/components/{email → auth/email}/email-changed.tsx +1 -1
- package/src/components/{email → auth/email}/email-verification.tsx +1 -1
- package/src/components/{email → auth/email}/magic-link.tsx +1 -1
- package/src/components/{email → auth/email}/new-device.tsx +1 -1
- package/src/components/{email → auth/email}/otp-email.tsx +1 -1
- package/src/components/{email → auth/email}/password-changed.tsx +1 -1
- package/src/components/{email → auth/email}/reset-password.tsx +1 -1
- package/src/email.ts +1 -0
- package/src/hooks/auth/use-authenticate.ts +12 -6
- package/src/hooks/auth/use-user.ts +14 -9
- package/src/hooks/use-auth-mutation.ts +30 -12
- package/src/hooks/use-auth-plugin.ts +50 -0
- package/src/hooks/use-auth-query.ts +11 -7
- package/src/index.ts +33 -32
- package/src/lib/auth-client.ts +33 -31
- package/src/lib/auth-plugin.ts +75 -0
- package/src/lib/auth-server.ts +30 -0
- package/src/mutations/auth/request-password-reset-mutation.ts +58 -0
- package/src/mutations/auth/reset-password-mutation.ts +60 -0
- package/src/mutations/auth/send-verification-email-mutation.ts +58 -0
- package/src/mutations/auth/sign-in-email-mutation.ts +78 -0
- package/src/mutations/auth/sign-in-social-mutation.ts +64 -0
- package/src/mutations/auth/sign-out-mutation.ts +71 -0
- package/src/mutations/auth/sign-up-email-mutation.ts +74 -0
- package/src/mutations/auth-mutation-options.ts +83 -38
- package/src/mutations/magic-link/sign-in-magic-link-mutation.ts +59 -0
- package/src/mutations/multi-session/revoke-multi-session-mutation.ts +70 -0
- package/src/mutations/multi-session/set-active-session-mutation.ts +98 -0
- package/src/mutations/passkey/add-passkey-mutation.ts +66 -0
- package/src/mutations/passkey/delete-passkey-mutation.ts +66 -0
- package/src/mutations/passkey/sign-in-passkey-mutation.ts +74 -0
- package/src/mutations/settings/change-email-mutation.ts +67 -0
- package/src/mutations/settings/change-password-mutation.ts +59 -0
- package/src/mutations/settings/delete-user-mutation.ts +59 -0
- package/src/mutations/settings/link-social-mutation.ts +59 -0
- package/src/mutations/settings/revoke-session-mutation.ts +69 -0
- package/src/mutations/settings/unlink-account-mutation.ts +67 -0
- package/src/mutations/settings/update-user-mutation.ts +82 -0
- package/src/mutations/username/is-username-available-mutation.ts +62 -0
- package/src/mutations/username/sign-in-username-mutation.ts +74 -0
- package/src/queries/auth/session-query.ts +135 -0
- package/src/queries/auth-query-options.ts +61 -12
- package/src/queries/multi-session/list-device-sessions-query.ts +177 -0
- package/src/queries/passkey/list-passkeys-query.ts +154 -0
- package/src/queries/settings/account-info-query.ts +158 -0
- package/src/queries/settings/list-accounts-query.ts +156 -0
- package/src/queries/settings/list-sessions-query.ts +154 -0
- package/src/server/queries/auth/session-query.ts +94 -0
- package/src/server/queries/multi-session/list-device-sessions-query.ts +102 -0
- package/src/server/queries/passkey/list-passkeys-query.ts +100 -0
- package/src/server/queries/settings/account-info-query.ts +101 -0
- package/src/server/queries/settings/list-accounts-query.ts +101 -0
- package/src/server/queries/settings/list-sessions-query.ts +101 -0
- package/src/server.ts +7 -0
- package/dist/core.d.ts +0 -1
- package/dist/core.js +0 -1
- package/dist/hooks/auth/use-is-username-available.d.ts +0 -20
- package/dist/hooks/auth/use-is-username-available.js +0 -13
- package/dist/hooks/auth/use-request-password-reset.d.ts +0 -21
- package/dist/hooks/auth/use-request-password-reset.js +0 -13
- package/dist/hooks/auth/use-reset-password.d.ts +0 -23
- package/dist/hooks/auth/use-reset-password.js +0 -13
- package/dist/hooks/auth/use-send-verification-email.d.ts +0 -19
- package/dist/hooks/auth/use-send-verification-email.js +0 -13
- package/dist/hooks/auth/use-session.d.ts +0 -35
- package/dist/hooks/auth/use-session.js +0 -16
- package/dist/hooks/auth/use-sign-in-email.d.ts +0 -26
- package/dist/hooks/auth/use-sign-in-email.js +0 -17
- package/dist/hooks/auth/use-sign-in-magic-link.d.ts +0 -27
- package/dist/hooks/auth/use-sign-in-magic-link.js +0 -13
- package/dist/hooks/auth/use-sign-in-passkey.d.ts +0 -21
- package/dist/hooks/auth/use-sign-in-passkey.js +0 -17
- package/dist/hooks/auth/use-sign-in-social.d.ts +0 -63
- package/dist/hooks/auth/use-sign-in-social.js +0 -13
- package/dist/hooks/auth/use-sign-in-username.d.ts +0 -25
- package/dist/hooks/auth/use-sign-in-username.js +0 -17
- package/dist/hooks/auth/use-sign-out.d.ts +0 -18
- package/dist/hooks/auth/use-sign-out.js +0 -16
- package/dist/hooks/auth/use-sign-up-email.d.ts +0 -1186
- package/dist/hooks/auth/use-sign-up-email.js +0 -17
- package/dist/hooks/settings/use-account-info.d.ts +0 -17
- package/dist/hooks/settings/use-account-info.js +0 -18
- package/dist/hooks/settings/use-add-passkey.d.ts +0 -21
- package/dist/hooks/settings/use-add-passkey.js +0 -17
- package/dist/hooks/settings/use-change-email.d.ts +0 -21
- package/dist/hooks/settings/use-change-email.js +0 -17
- package/dist/hooks/settings/use-change-password.d.ts +0 -21
- package/dist/hooks/settings/use-change-password.js +0 -13
- package/dist/hooks/settings/use-delete-passkey.d.ts +0 -19
- package/dist/hooks/settings/use-delete-passkey.js +0 -17
- package/dist/hooks/settings/use-delete-user.d.ts +0 -24
- package/dist/hooks/settings/use-delete-user.js +0 -13
- package/dist/hooks/settings/use-link-social.d.ts +0 -43
- package/dist/hooks/settings/use-link-social.js +0 -13
- package/dist/hooks/settings/use-list-accounts.d.ts +0 -22
- package/dist/hooks/settings/use-list-accounts.js +0 -15
- package/dist/hooks/settings/use-list-device-sessions.d.ts +0 -34
- package/dist/hooks/settings/use-list-device-sessions.js +0 -15
- package/dist/hooks/settings/use-list-sessions.d.ts +0 -23
- package/dist/hooks/settings/use-list-sessions.js +0 -15
- package/dist/hooks/settings/use-list-user-passkeys.d.ts +0 -14
- package/dist/hooks/settings/use-list-user-passkeys.js +0 -15
- package/dist/hooks/settings/use-revoke-multi-session.d.ts +0 -19
- package/dist/hooks/settings/use-revoke-multi-session.js +0 -17
- package/dist/hooks/settings/use-revoke-session.d.ts +0 -19
- package/dist/hooks/settings/use-revoke-session.js +0 -17
- package/dist/hooks/settings/use-set-active-session.d.ts +0 -20
- package/dist/hooks/settings/use-set-active-session.js +0 -20
- package/dist/hooks/settings/use-unlink-account.d.ts +0 -21
- package/dist/hooks/settings/use-unlink-account.js +0 -17
- package/dist/hooks/settings/use-update-user.d.ts +0 -1185
- package/dist/hooks/settings/use-update-user.js +0 -24
- package/dist/lib/auth-client.js +0 -11
- package/dist/lib/auth-config.d.ts +0 -43
- package/dist/lib/auth-context.d.ts +0 -2
- package/dist/lib/auth-context.js +0 -6
- package/dist/mutations/auth/is-username-available-options.d.ts +0 -19
- package/dist/mutations/auth/is-username-available-options.js +0 -7
- package/dist/mutations/auth/request-password-reset-options.d.ts +0 -15
- package/dist/mutations/auth/request-password-reset-options.js +0 -7
- package/dist/mutations/auth/reset-password-options.d.ts +0 -17
- package/dist/mutations/auth/reset-password-options.js +0 -7
- package/dist/mutations/auth/send-verification-email-options.d.ts +0 -15
- package/dist/mutations/auth/send-verification-email-options.js +0 -7
- package/dist/mutations/auth/sign-in-email-options.d.ts +0 -23
- package/dist/mutations/auth/sign-in-email-options.js +0 -11
- package/dist/mutations/auth/sign-in-magic-link-options.d.ts +0 -23
- package/dist/mutations/auth/sign-in-magic-link-options.js +0 -11
- package/dist/mutations/auth/sign-in-passkey-options.d.ts +0 -15
- package/dist/mutations/auth/sign-in-passkey-options.js +0 -11
- package/dist/mutations/auth/sign-in-social-options.d.ts +0 -61
- package/dist/mutations/auth/sign-in-social-options.js +0 -11
- package/dist/mutations/auth/sign-in-username-options.d.ts +0 -19
- package/dist/mutations/auth/sign-in-username-options.js +0 -11
- package/dist/mutations/auth/sign-out-options.d.ts +0 -12
- package/dist/mutations/auth/sign-out-options.js +0 -7
- package/dist/mutations/auth/sign-up-email-options.d.ts +0 -1180
- package/dist/mutations/auth/sign-up-email-options.js +0 -11
- package/dist/mutations/settings/add-passkey-options.d.ts +0 -15
- package/dist/mutations/settings/add-passkey-options.js +0 -11
- package/dist/mutations/settings/change-email-options.d.ts +0 -15
- package/dist/mutations/settings/change-email-options.js +0 -7
- package/dist/mutations/settings/change-password-options.d.ts +0 -17
- package/dist/mutations/settings/change-password-options.js +0 -7
- package/dist/mutations/settings/delete-passkey-options.d.ts +0 -13
- package/dist/mutations/settings/delete-passkey-options.js +0 -11
- package/dist/mutations/settings/delete-user-options.d.ts +0 -20
- package/dist/mutations/settings/delete-user-options.js +0 -7
- package/dist/mutations/settings/link-social-options.d.ts +0 -39
- package/dist/mutations/settings/link-social-options.js +0 -7
- package/dist/mutations/settings/revoke-multi-session-options.d.ts +0 -13
- package/dist/mutations/settings/revoke-multi-session-options.js +0 -11
- package/dist/mutations/settings/revoke-session-options.d.ts +0 -13
- package/dist/mutations/settings/revoke-session-options.js +0 -7
- package/dist/mutations/settings/set-active-session-options.d.ts +0 -13
- package/dist/mutations/settings/set-active-session-options.js +0 -11
- package/dist/mutations/settings/unlink-account-options.d.ts +0 -15
- package/dist/mutations/settings/unlink-account-options.js +0 -7
- package/dist/mutations/settings/update-user-options.d.ts +0 -1182
- package/dist/mutations/settings/update-user-options.js +0 -7
- package/dist/queries/auth/session-options.d.ts +0 -110
- package/dist/queries/auth/session-options.js +0 -7
- package/dist/queries/settings/account-info-options.d.ts +0 -32
- package/dist/queries/settings/account-info-options.js +0 -12
- package/dist/queries/settings/list-accounts-options.d.ts +0 -53
- package/dist/queries/settings/list-accounts-options.js +0 -12
- package/dist/queries/settings/list-device-sessions-options.d.ts +0 -99
- package/dist/queries/settings/list-device-sessions-options.js +0 -12
- package/dist/queries/settings/list-sessions-options.d.ts +0 -54
- package/dist/queries/settings/list-sessions-options.js +0 -12
- package/dist/queries/settings/list-user-passkeys-options.d.ts +0 -18
- package/dist/queries/settings/list-user-passkeys-options.js +0 -12
- package/src/core.ts +0 -1
- package/src/hooks/auth/use-is-username-available.ts +0 -31
- package/src/hooks/auth/use-request-password-reset.ts +0 -33
- package/src/hooks/auth/use-reset-password.ts +0 -31
- package/src/hooks/auth/use-send-verification-email.ts +0 -31
- package/src/hooks/auth/use-session.ts +0 -31
- package/src/hooks/auth/use-sign-in-email.ts +0 -41
- package/src/hooks/auth/use-sign-in-magic-link.ts +0 -29
- package/src/hooks/auth/use-sign-in-passkey.ts +0 -40
- package/src/hooks/auth/use-sign-in-social.ts +0 -31
- package/src/hooks/auth/use-sign-in-username.ts +0 -40
- package/src/hooks/auth/use-sign-out.ts +0 -34
- package/src/hooks/auth/use-sign-up-email.ts +0 -40
- package/src/hooks/settings/use-account-info.ts +0 -40
- package/src/hooks/settings/use-add-passkey.ts +0 -37
- package/src/hooks/settings/use-change-email.ts +0 -37
- package/src/hooks/settings/use-change-password.ts +0 -29
- package/src/hooks/settings/use-delete-passkey.ts +0 -37
- package/src/hooks/settings/use-delete-user.ts +0 -29
- package/src/hooks/settings/use-link-social.ts +0 -29
- package/src/hooks/settings/use-list-accounts.ts +0 -39
- package/src/hooks/settings/use-list-device-sessions.ts +0 -39
- package/src/hooks/settings/use-list-sessions.ts +0 -39
- package/src/hooks/settings/use-list-user-passkeys.ts +0 -39
- package/src/hooks/settings/use-revoke-multi-session.ts +0 -39
- package/src/hooks/settings/use-revoke-session.ts +0 -39
- package/src/hooks/settings/use-set-active-session.ts +0 -58
- package/src/hooks/settings/use-unlink-account.ts +0 -37
- package/src/hooks/settings/use-update-user.ts +0 -50
- package/src/lib/auth-config.ts +0 -48
- package/src/lib/auth-context.ts +0 -6
- package/src/mutations/auth/is-username-available-options.ts +0 -18
- package/src/mutations/auth/request-password-reset-options.ts +0 -14
- package/src/mutations/auth/reset-password-options.ts +0 -14
- package/src/mutations/auth/send-verification-email-options.ts +0 -14
- package/src/mutations/auth/sign-in-email-options.ts +0 -19
- package/src/mutations/auth/sign-in-magic-link-options.ts +0 -15
- package/src/mutations/auth/sign-in-passkey-options.ts +0 -15
- package/src/mutations/auth/sign-in-social-options.ts +0 -19
- package/src/mutations/auth/sign-in-username-options.ts +0 -15
- package/src/mutations/auth/sign-out-options.ts +0 -11
- package/src/mutations/auth/sign-up-email-options.ts +0 -15
- package/src/mutations/settings/add-passkey-options.ts +0 -15
- package/src/mutations/settings/change-email-options.ts +0 -11
- package/src/mutations/settings/change-password-options.ts +0 -14
- package/src/mutations/settings/delete-passkey-options.ts +0 -15
- package/src/mutations/settings/delete-user-options.ts +0 -11
- package/src/mutations/settings/link-social-options.ts +0 -11
- package/src/mutations/settings/revoke-multi-session-options.ts +0 -15
- package/src/mutations/settings/revoke-session-options.ts +0 -14
- package/src/mutations/settings/set-active-session-options.ts +0 -15
- package/src/mutations/settings/unlink-account-options.ts +0 -14
- package/src/mutations/settings/update-user-options.ts +0 -15
- package/src/queries/auth/session-options.ts +0 -18
- package/src/queries/settings/account-info-options.ts +0 -25
- package/src/queries/settings/list-accounts-options.ts +0 -26
- package/src/queries/settings/list-device-sessions-options.ts +0 -24
- package/src/queries/settings/list-sessions-options.ts +0 -23
- package/src/queries/settings/list-user-passkeys-options.ts +0 -23
- /package/dist/components/{email → auth/email}/email-changed.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-localization.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-styles.d.ts +0 -0
- /package/dist/components/{email → auth/email}/email-verification.d.ts +0 -0
- /package/dist/components/{email → auth/email}/index.d.ts +0 -0
- /package/dist/components/{email → auth/email}/index.js +0 -0
- /package/dist/components/{email → auth/email}/magic-link.d.ts +0 -0
- /package/dist/components/{email → auth/email}/new-device.d.ts +0 -0
- /package/dist/components/{email → auth/email}/otp-email.d.ts +0 -0
- /package/dist/components/{email → auth/email}/password-changed.d.ts +0 -0
- /package/dist/components/{email → auth/email}/reset-password.d.ts +0 -0
- /package/src/components/{email → auth/email}/email-localization.tsx +0 -0
- /package/src/components/{email → auth/email}/email-styles.tsx +0 -0
- /package/src/components/{email → auth/email}/index.ts +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { passkey } from "@better-auth/passkey"
|
|
2
|
+
import type { Auth } from "better-auth"
|
|
3
|
+
import type { magicLink, multiSession, username } from "better-auth/plugins"
|
|
4
|
+
|
|
5
|
+
export type AuthServer = Pick<Auth, "api">
|
|
6
|
+
|
|
7
|
+
// Per-plugin variants mirror the client-side types in `auth-client.ts` so
|
|
8
|
+
// server-side query factories can depend on a narrow `auth` shape that
|
|
9
|
+
// includes the plugin's API surface without requiring the full `betterAuth`
|
|
10
|
+
// return type to be threaded through as a generic.
|
|
11
|
+
|
|
12
|
+
export type MagicLinkAuthServer = Pick<
|
|
13
|
+
Auth<{ plugins: [ReturnType<typeof magicLink>] }>,
|
|
14
|
+
"api"
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
export type MultiSessionAuthServer = Pick<
|
|
18
|
+
Auth<{ plugins: [ReturnType<typeof multiSession>] }>,
|
|
19
|
+
"api"
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
export type PasskeyAuthServer = Pick<
|
|
23
|
+
Auth<{ plugins: [ReturnType<typeof passkey>] }>,
|
|
24
|
+
"api"
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export type UsernameAuthServer = Pick<
|
|
28
|
+
Auth<{ plugins: [ReturnType<typeof username>] }>,
|
|
29
|
+
"api"
|
|
30
|
+
>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
6
|
+
|
|
7
|
+
export type RequestPasswordResetParams<TAuthClient extends AuthClient> =
|
|
8
|
+
Parameters<TAuthClient["requestPasswordReset"]>[0]
|
|
9
|
+
|
|
10
|
+
export type RequestPasswordResetOptions<TAuthClient extends AuthClient> = Omit<
|
|
11
|
+
ReturnType<typeof requestPasswordResetOptions<TAuthClient>>,
|
|
12
|
+
"mutationKey" | "mutationFn"
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mutation options factory for requesting a password reset email.
|
|
17
|
+
*
|
|
18
|
+
* @param authClient - The Better Auth client.
|
|
19
|
+
*/
|
|
20
|
+
export function requestPasswordResetOptions<TAuthClient extends AuthClient>(
|
|
21
|
+
authClient: TAuthClient
|
|
22
|
+
) {
|
|
23
|
+
const mutationKey = authMutationKeys.requestPasswordReset
|
|
24
|
+
|
|
25
|
+
const mutationFn = (params: RequestPasswordResetParams<TAuthClient>) =>
|
|
26
|
+
authClient.requestPasswordReset({
|
|
27
|
+
...params,
|
|
28
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return mutationOptions<
|
|
32
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
33
|
+
BetterFetchError,
|
|
34
|
+
Parameters<typeof mutationFn>[0]
|
|
35
|
+
>({
|
|
36
|
+
mutationKey,
|
|
37
|
+
mutationFn
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a mutation for requesting a password reset email.
|
|
43
|
+
*
|
|
44
|
+
* Wraps `authClient.requestPasswordReset` and forwards React Query mutation
|
|
45
|
+
* options such as `onSuccess`, `onError`, and `retry`.
|
|
46
|
+
*
|
|
47
|
+
* @param authClient - The Better Auth client.
|
|
48
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
49
|
+
*/
|
|
50
|
+
export function useRequestPasswordReset<TAuthClient extends AuthClient>(
|
|
51
|
+
authClient: TAuthClient,
|
|
52
|
+
options?: RequestPasswordResetOptions<TAuthClient>
|
|
53
|
+
) {
|
|
54
|
+
return useMutation({
|
|
55
|
+
...requestPasswordResetOptions(authClient),
|
|
56
|
+
...options
|
|
57
|
+
})
|
|
58
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
6
|
+
|
|
7
|
+
export type ResetPasswordParams<TAuthClient extends AuthClient> = Parameters<
|
|
8
|
+
TAuthClient["resetPassword"]
|
|
9
|
+
>[0]
|
|
10
|
+
|
|
11
|
+
export type ResetPasswordOptions<TAuthClient extends AuthClient> = Omit<
|
|
12
|
+
ReturnType<typeof resetPasswordOptions<TAuthClient>>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Mutation options factory for completing a password reset.
|
|
18
|
+
*
|
|
19
|
+
* @param authClient - The Better Auth client.
|
|
20
|
+
*/
|
|
21
|
+
export function resetPasswordOptions<TAuthClient extends AuthClient>(
|
|
22
|
+
authClient: TAuthClient
|
|
23
|
+
) {
|
|
24
|
+
const mutationKey = authMutationKeys.resetPassword
|
|
25
|
+
|
|
26
|
+
const mutationFn = (params: ResetPasswordParams<TAuthClient>) =>
|
|
27
|
+
authClient.resetPassword({
|
|
28
|
+
...params,
|
|
29
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return mutationOptions<
|
|
33
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
34
|
+
BetterFetchError,
|
|
35
|
+
Parameters<typeof mutationFn>[0]
|
|
36
|
+
>({
|
|
37
|
+
mutationKey,
|
|
38
|
+
mutationFn
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a mutation for completing a password reset.
|
|
44
|
+
*
|
|
45
|
+
* Wraps `authClient.resetPassword` (using the token from the reset email)
|
|
46
|
+
* and forwards React Query mutation options such as `onSuccess`, `onError`,
|
|
47
|
+
* and `retry`.
|
|
48
|
+
*
|
|
49
|
+
* @param authClient - The Better Auth client.
|
|
50
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
51
|
+
*/
|
|
52
|
+
export function useResetPassword<TAuthClient extends AuthClient>(
|
|
53
|
+
authClient: TAuthClient,
|
|
54
|
+
options?: ResetPasswordOptions<TAuthClient>
|
|
55
|
+
) {
|
|
56
|
+
return useMutation({
|
|
57
|
+
...resetPasswordOptions(authClient),
|
|
58
|
+
...options
|
|
59
|
+
})
|
|
60
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
6
|
+
|
|
7
|
+
export type SendVerificationEmailParams<TAuthClient extends AuthClient> =
|
|
8
|
+
Parameters<TAuthClient["sendVerificationEmail"]>[0]
|
|
9
|
+
|
|
10
|
+
export type SendVerificationEmailOptions<TAuthClient extends AuthClient> = Omit<
|
|
11
|
+
ReturnType<typeof sendVerificationEmailOptions<TAuthClient>>,
|
|
12
|
+
"mutationKey" | "mutationFn"
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mutation options factory for sending a verification email.
|
|
17
|
+
*
|
|
18
|
+
* @param authClient - The Better Auth client.
|
|
19
|
+
*/
|
|
20
|
+
export function sendVerificationEmailOptions<TAuthClient extends AuthClient>(
|
|
21
|
+
authClient: TAuthClient
|
|
22
|
+
) {
|
|
23
|
+
const mutationKey = authMutationKeys.sendVerificationEmail
|
|
24
|
+
|
|
25
|
+
const mutationFn = (params: SendVerificationEmailParams<TAuthClient>) =>
|
|
26
|
+
authClient.sendVerificationEmail({
|
|
27
|
+
...params,
|
|
28
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return mutationOptions<
|
|
32
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
33
|
+
BetterFetchError,
|
|
34
|
+
Parameters<typeof mutationFn>[0]
|
|
35
|
+
>({
|
|
36
|
+
mutationKey,
|
|
37
|
+
mutationFn
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a mutation for sending an email-verification link.
|
|
43
|
+
*
|
|
44
|
+
* Wraps `authClient.sendVerificationEmail` and forwards React Query mutation
|
|
45
|
+
* options such as `onSuccess`, `onError`, and `retry`.
|
|
46
|
+
*
|
|
47
|
+
* @param authClient - The Better Auth client.
|
|
48
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
49
|
+
*/
|
|
50
|
+
export function useSendVerificationEmail<TAuthClient extends AuthClient>(
|
|
51
|
+
authClient: TAuthClient,
|
|
52
|
+
options?: SendVerificationEmailOptions<TAuthClient>
|
|
53
|
+
) {
|
|
54
|
+
return useMutation({
|
|
55
|
+
...sendVerificationEmailOptions(authClient),
|
|
56
|
+
...options
|
|
57
|
+
})
|
|
58
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import {
|
|
3
|
+
mutationOptions,
|
|
4
|
+
useMutation,
|
|
5
|
+
useQueryClient
|
|
6
|
+
} from "@tanstack/react-query"
|
|
7
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
8
|
+
|
|
9
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
10
|
+
import { sessionOptions } from "../../queries/auth/session-query"
|
|
11
|
+
|
|
12
|
+
export type SignInEmailParams<TAuthClient extends AuthClient> = Parameters<
|
|
13
|
+
TAuthClient["signIn"]["email"]
|
|
14
|
+
>[0]
|
|
15
|
+
|
|
16
|
+
export type SignInEmailOptions<TAuthClient extends AuthClient> = Omit<
|
|
17
|
+
ReturnType<typeof signInEmailOptions<TAuthClient>>,
|
|
18
|
+
"mutationKey" | "mutationFn"
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Mutation options factory for email/password sign-in.
|
|
23
|
+
*
|
|
24
|
+
* The returned `mutationKey` (`authMutationKeys.signIn.email`) is stable and
|
|
25
|
+
* can be passed to `useIsMutating` or matched inside a global
|
|
26
|
+
* `MutationCache` observer for toast handling.
|
|
27
|
+
*
|
|
28
|
+
* @param authClient - The Better Auth client.
|
|
29
|
+
*/
|
|
30
|
+
export function signInEmailOptions<TAuthClient extends AuthClient>(
|
|
31
|
+
authClient: TAuthClient
|
|
32
|
+
) {
|
|
33
|
+
const mutationKey = authMutationKeys.signIn.email
|
|
34
|
+
|
|
35
|
+
const mutationFn = (params: SignInEmailParams<TAuthClient>) =>
|
|
36
|
+
authClient.signIn.email({
|
|
37
|
+
...params,
|
|
38
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return mutationOptions<
|
|
42
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
43
|
+
BetterFetchError,
|
|
44
|
+
Parameters<typeof mutationFn>[0]
|
|
45
|
+
>({
|
|
46
|
+
mutationKey,
|
|
47
|
+
mutationFn
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a mutation for email/password sign-in.
|
|
53
|
+
*
|
|
54
|
+
* Wraps `authClient.signIn.email`, resets the session query on success so
|
|
55
|
+
* the new session is refetched, and forwards React Query mutation options
|
|
56
|
+
* such as `onSuccess`, `onError`, and `retry`.
|
|
57
|
+
*
|
|
58
|
+
* @param authClient - The Better Auth client.
|
|
59
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
60
|
+
*/
|
|
61
|
+
export function useSignInEmail<TAuthClient extends AuthClient>(
|
|
62
|
+
authClient: TAuthClient,
|
|
63
|
+
options?: SignInEmailOptions<TAuthClient>
|
|
64
|
+
) {
|
|
65
|
+
const queryClient = useQueryClient()
|
|
66
|
+
|
|
67
|
+
return useMutation({
|
|
68
|
+
...signInEmailOptions(authClient),
|
|
69
|
+
...options,
|
|
70
|
+
onSuccess: async (...args) => {
|
|
71
|
+
queryClient.resetQueries({
|
|
72
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
await options?.onSuccess?.(...args)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import { mutationOptions, useMutation } from "@tanstack/react-query"
|
|
3
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
4
|
+
|
|
5
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
6
|
+
|
|
7
|
+
export type SignInSocialParams<TAuthClient extends AuthClient> = Parameters<
|
|
8
|
+
TAuthClient["signIn"]["social"]
|
|
9
|
+
>[0]
|
|
10
|
+
|
|
11
|
+
export type SignInSocialOptions<TAuthClient extends AuthClient> = Omit<
|
|
12
|
+
ReturnType<typeof signInSocialOptions<TAuthClient>>,
|
|
13
|
+
"mutationKey" | "mutationFn"
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Mutation options factory for social sign-in.
|
|
18
|
+
*
|
|
19
|
+
* The returned `mutationKey` (`["auth", "signIn", "social"]`) is stable and
|
|
20
|
+
* can be passed to `useIsMutating` or matched inside a global
|
|
21
|
+
* `MutationCache` observer for toast handling.
|
|
22
|
+
*
|
|
23
|
+
* @param authClient - The Better Auth client.
|
|
24
|
+
*/
|
|
25
|
+
export function signInSocialOptions<TAuthClient extends AuthClient>(
|
|
26
|
+
authClient: TAuthClient
|
|
27
|
+
) {
|
|
28
|
+
const mutationKey = authMutationKeys.signIn.social
|
|
29
|
+
|
|
30
|
+
const mutationFn = (params: SignInSocialParams<TAuthClient>) =>
|
|
31
|
+
authClient.signIn.social({
|
|
32
|
+
...params,
|
|
33
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return mutationOptions<
|
|
37
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
38
|
+
BetterFetchError,
|
|
39
|
+
Parameters<typeof mutationFn>[0]
|
|
40
|
+
>({
|
|
41
|
+
mutationKey,
|
|
42
|
+
mutationFn
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a mutation for social sign-in.
|
|
48
|
+
*
|
|
49
|
+
* Wraps `authClient.signIn.social` to initiate a provider redirect and
|
|
50
|
+
* forwards React Query mutation options such as `onSuccess`, `onError`,
|
|
51
|
+
* and `retry`.
|
|
52
|
+
*
|
|
53
|
+
* @param authClient - The Better Auth client.
|
|
54
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
55
|
+
*/
|
|
56
|
+
export function useSignInSocial<TAuthClient extends AuthClient>(
|
|
57
|
+
authClient: TAuthClient,
|
|
58
|
+
options?: SignInSocialOptions<TAuthClient>
|
|
59
|
+
) {
|
|
60
|
+
return useMutation({
|
|
61
|
+
...signInSocialOptions(authClient),
|
|
62
|
+
...options
|
|
63
|
+
})
|
|
64
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { authMutationKeys, authQueryKeys } from "@better-auth-ui/core"
|
|
2
|
+
import {
|
|
3
|
+
mutationOptions,
|
|
4
|
+
useMutation,
|
|
5
|
+
useQueryClient
|
|
6
|
+
} from "@tanstack/react-query"
|
|
7
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
8
|
+
|
|
9
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
10
|
+
|
|
11
|
+
export type SignOutParams<TAuthClient extends AuthClient> = Parameters<
|
|
12
|
+
TAuthClient["signOut"]
|
|
13
|
+
>[0]
|
|
14
|
+
|
|
15
|
+
export type SignOutOptions<TAuthClient extends AuthClient> = Omit<
|
|
16
|
+
ReturnType<typeof signOutOptions<TAuthClient>>,
|
|
17
|
+
"mutationKey" | "mutationFn"
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Mutation options factory for signing out.
|
|
22
|
+
*
|
|
23
|
+
* @param authClient - The Better Auth client.
|
|
24
|
+
*/
|
|
25
|
+
export function signOutOptions<TAuthClient extends AuthClient>(
|
|
26
|
+
authClient: TAuthClient
|
|
27
|
+
) {
|
|
28
|
+
const mutationKey = authMutationKeys.signOut
|
|
29
|
+
|
|
30
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: void allows no-arg mutate
|
|
31
|
+
const mutationFn = (params?: SignOutParams<TAuthClient> | void) =>
|
|
32
|
+
authClient.signOut({
|
|
33
|
+
...(params ?? {}),
|
|
34
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return mutationOptions<
|
|
38
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
39
|
+
BetterFetchError,
|
|
40
|
+
Parameters<typeof mutationFn>[0]
|
|
41
|
+
>({
|
|
42
|
+
mutationKey,
|
|
43
|
+
mutationFn
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a mutation for signing the current user out.
|
|
49
|
+
*
|
|
50
|
+
* Wraps `authClient.signOut`, removes all cached auth queries on success,
|
|
51
|
+
* and forwards React Query mutation options such as `onSuccess`, `onError`,
|
|
52
|
+
* and `retry`.
|
|
53
|
+
*
|
|
54
|
+
* @param authClient - The Better Auth client.
|
|
55
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
56
|
+
*/
|
|
57
|
+
export function useSignOut<TAuthClient extends AuthClient>(
|
|
58
|
+
authClient: TAuthClient,
|
|
59
|
+
options?: SignOutOptions<TAuthClient>
|
|
60
|
+
) {
|
|
61
|
+
const queryClient = useQueryClient()
|
|
62
|
+
|
|
63
|
+
return useMutation({
|
|
64
|
+
...signOutOptions(authClient),
|
|
65
|
+
...options,
|
|
66
|
+
onSuccess: async (...args) => {
|
|
67
|
+
queryClient.removeQueries({ queryKey: authQueryKeys.all })
|
|
68
|
+
await options?.onSuccess?.(...args)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { authMutationKeys } from "@better-auth-ui/core"
|
|
2
|
+
import {
|
|
3
|
+
mutationOptions,
|
|
4
|
+
useMutation,
|
|
5
|
+
useQueryClient
|
|
6
|
+
} from "@tanstack/react-query"
|
|
7
|
+
import type { BetterFetchError } from "better-auth/react"
|
|
8
|
+
|
|
9
|
+
import type { AuthClient } from "../../lib/auth-client"
|
|
10
|
+
import { sessionOptions } from "../../queries/auth/session-query"
|
|
11
|
+
|
|
12
|
+
export type SignUpEmailParams<TAuthClient extends AuthClient> = Parameters<
|
|
13
|
+
TAuthClient["signUp"]["email"]
|
|
14
|
+
>[0]
|
|
15
|
+
|
|
16
|
+
export type SignUpEmailOptions<TAuthClient extends AuthClient> = Omit<
|
|
17
|
+
ReturnType<typeof signUpEmailOptions<TAuthClient>>,
|
|
18
|
+
"mutationKey" | "mutationFn"
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Mutation options factory for email/password sign-up.
|
|
23
|
+
*
|
|
24
|
+
* @param authClient - The Better Auth client.
|
|
25
|
+
*/
|
|
26
|
+
export function signUpEmailOptions<TAuthClient extends AuthClient>(
|
|
27
|
+
authClient: TAuthClient
|
|
28
|
+
) {
|
|
29
|
+
const mutationKey = authMutationKeys.signUp.email
|
|
30
|
+
|
|
31
|
+
const mutationFn = (params: SignUpEmailParams<TAuthClient>) =>
|
|
32
|
+
authClient.signUp.email({
|
|
33
|
+
...params,
|
|
34
|
+
fetchOptions: { ...params?.fetchOptions, throw: true }
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return mutationOptions<
|
|
38
|
+
Awaited<ReturnType<typeof mutationFn>>,
|
|
39
|
+
BetterFetchError,
|
|
40
|
+
Parameters<typeof mutationFn>[0]
|
|
41
|
+
>({
|
|
42
|
+
mutationKey,
|
|
43
|
+
mutationFn
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a mutation for email/password sign-up.
|
|
49
|
+
*
|
|
50
|
+
* Wraps `authClient.signUp.email`, resets the session query on success so
|
|
51
|
+
* the new session is refetched, and forwards React Query mutation options
|
|
52
|
+
* such as `onSuccess`, `onError`, and `retry`.
|
|
53
|
+
*
|
|
54
|
+
* @param authClient - The Better Auth client.
|
|
55
|
+
* @param options - React Query options forwarded to `useMutation`.
|
|
56
|
+
*/
|
|
57
|
+
export function useSignUpEmail<TAuthClient extends AuthClient>(
|
|
58
|
+
authClient: TAuthClient,
|
|
59
|
+
options?: SignUpEmailOptions<TAuthClient>
|
|
60
|
+
) {
|
|
61
|
+
const queryClient = useQueryClient()
|
|
62
|
+
|
|
63
|
+
return useMutation({
|
|
64
|
+
...signUpEmailOptions(authClient),
|
|
65
|
+
...options,
|
|
66
|
+
onSuccess: async (...args) => {
|
|
67
|
+
queryClient.resetQueries({
|
|
68
|
+
queryKey: sessionOptions(authClient).queryKey
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
await options?.onSuccess?.(...args)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
@@ -1,49 +1,94 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type MutationKey,
|
|
3
|
+
mutationOptions,
|
|
4
|
+
type UseMutationOptions
|
|
5
|
+
} from "@tanstack/react-query"
|
|
2
6
|
import type { BetterFetchError, BetterFetchOption } from "better-auth/client"
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Write-style Better Auth client method. Variables are a single object that
|
|
10
|
+
* may carry top-level params plus `fetchOptions` (e.g. `signIn.email` takes
|
|
11
|
+
* `{ email, password, rememberMe?, fetchOptions? }`).
|
|
12
|
+
*
|
|
13
|
+
* Read-style endpoints use `AuthQueryFn` / `useAuthQuery` instead.
|
|
14
|
+
*/
|
|
15
|
+
export type AuthMutationFn = (
|
|
16
|
+
// biome-ignore lint/suspicious/noExplicitAny: variance bridge for arbitrary Better Auth client methods
|
|
17
|
+
variables: any
|
|
18
|
+
) => Promise<unknown>
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Resolved data type returned by an {@link AuthMutationFn}.
|
|
22
|
+
*/
|
|
23
|
+
export type AuthMutationFnData<TFn extends AuthMutationFn> = Awaited<
|
|
24
|
+
ReturnType<TFn>
|
|
25
|
+
>
|
|
17
26
|
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
28
|
+
* Variables type accepted by `mutate` / `mutateAsync` for a given
|
|
29
|
+
* {@link AuthMutationFn}.
|
|
20
30
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
31
|
+
* If the method's params are entirely optional (e.g. `authClient.signOut`),
|
|
32
|
+
* this resolves to `Variables | void` so `mutate()` is callable without
|
|
33
|
+
* arguments. Otherwise it resolves to the exact required shape so the type
|
|
34
|
+
* checker rejects `mutate()` when the underlying call needs params.
|
|
35
|
+
*/
|
|
36
|
+
export type AuthMutationFnVariables<TFn extends AuthMutationFn> =
|
|
37
|
+
Parameters<TFn>[0] extends infer P
|
|
38
|
+
? undefined extends P
|
|
39
|
+
? // biome-ignore lint/suspicious/noConfusingVoidType: void allows no-arg mutate
|
|
40
|
+
NonNullable<P> | void
|
|
41
|
+
: P
|
|
42
|
+
: never
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return type of {@link authMutationOptions}, matching the shape produced by
|
|
46
|
+
* TanStack Query's own `mutationOptions` helper.
|
|
47
|
+
*/
|
|
48
|
+
export type AuthMutationOptions<
|
|
49
|
+
TFn extends AuthMutationFn,
|
|
50
|
+
TMutationKey extends MutationKey = MutationKey
|
|
51
|
+
> = Omit<
|
|
52
|
+
UseMutationOptions<
|
|
53
|
+
AuthMutationFnData<TFn>,
|
|
54
|
+
BetterFetchError,
|
|
55
|
+
AuthMutationFnVariables<TFn>
|
|
56
|
+
>,
|
|
57
|
+
"mutationKey"
|
|
58
|
+
> & {
|
|
59
|
+
mutationKey: TMutationKey
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Build `mutationOptions` for a write-style Better Auth endpoint.
|
|
23
64
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `TData` explicitly (e.g. `authMutationOptions<_, _, { available: boolean }>`).
|
|
65
|
+
* Injects `throw: true` into `fetchOptions` so the promise rejects with a
|
|
66
|
+
* `BetterFetchError` on failure instead of resolving to `{ data, error }`.
|
|
27
67
|
*
|
|
28
|
-
* @param authFn - Better Auth client method (e.g. `authClient.
|
|
29
|
-
* @param mutationKey -
|
|
68
|
+
* @param authFn - Better Auth client method (e.g. `authClient.emailOtp.sendVerificationOtp`).
|
|
69
|
+
* @param mutationKey - Stable key for the mutation (used by `useIsMutating`, `MutationCache`, …).
|
|
30
70
|
*/
|
|
31
71
|
export function authMutationOptions<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
TFn extends AuthMutationFn,
|
|
73
|
+
const TMutationKey extends MutationKey
|
|
74
|
+
>(
|
|
75
|
+
authFn: TFn,
|
|
76
|
+
mutationKey: TMutationKey
|
|
77
|
+
): AuthMutationOptions<TFn, TMutationKey> {
|
|
78
|
+
const mutationFn = (variables: AuthMutationFnVariables<TFn>) => {
|
|
79
|
+
const vars = (variables ?? {}) as { fetchOptions?: BetterFetchOption }
|
|
80
|
+
return authFn({
|
|
81
|
+
...vars,
|
|
82
|
+
fetchOptions: { ...vars.fetchOptions, throw: true }
|
|
83
|
+
}) as Promise<AuthMutationFnData<TFn>>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return mutationOptions<
|
|
87
|
+
AuthMutationFnData<TFn>,
|
|
88
|
+
BetterFetchError,
|
|
89
|
+
AuthMutationFnVariables<TFn>
|
|
90
|
+
>({
|
|
91
|
+
mutationKey,
|
|
92
|
+
mutationFn
|
|
93
|
+
}) as AuthMutationOptions<TFn, TMutationKey>
|
|
49
94
|
}
|