({
onRedirect,
onInvalidRegistration,
onInitializeVerification,
}: UseRegistrationProps)
| 48 | "We couldn't complete sign up. If you already have an account, try signing in instead."; |
| 49 | |
| 50 | const useRegistration = ({ |
| 51 | onRedirect, |
| 52 | onInvalidRegistration, |
| 53 | onInitializeVerification, |
| 54 | }: UseRegistrationProps): UseRegistration => { |
| 55 | const { logEvent } = useLogContext(); |
| 56 | const { displayToast } = useToastNotification(); |
| 57 | const { referral, referralOrigin, geo, refetchBoot } = |
| 58 | useContext(AuthContext); |
| 59 | const timezone = getUserDefaultTimezone(); |
| 60 | |
| 61 | const { |
| 62 | mutateAsync: betterAuthRegister, |
| 63 | status, |
| 64 | isPending: isBetterAuthMutationLoading, |
| 65 | } = useMutation({ |
| 66 | mutationFn: async (params: { |
| 67 | name: string; |
| 68 | email: string; |
| 69 | password: string; |
| 70 | turnstileToken?: string; |
| 71 | username?: string; |
| 72 | experienceLevel?: string; |
| 73 | company?: string; |
| 74 | title?: string; |
| 75 | cloudProvider?: string; |
| 76 | referral?: string; |
| 77 | referralOrigin?: string; |
| 78 | timezone?: string; |
| 79 | region?: string; |
| 80 | acceptedMarketing?: boolean; |
| 81 | }) => { |
| 82 | logEvent({ |
| 83 | event_name: 'click', |
| 84 | target_type: AuthEventNames.SignUpProvider, |
| 85 | target_id: 'email', |
| 86 | extra: JSON.stringify({ trigger: 'registration' }), |
| 87 | }); |
| 88 | return betterAuthSignUp({ |
| 89 | ...params, |
| 90 | }); |
| 91 | }, |
| 92 | onSuccess: async (res) => { |
| 93 | if (res.error) { |
| 94 | logEvent({ |
| 95 | event_name: AuthEventNames.RegistrationError, |
| 96 | extra: JSON.stringify({ |
| 97 | provider: 'password', |
| 98 | error: res.error, |
| 99 | origin: 'betterauth signup error', |
| 100 | }), |
| 101 | }); |
| 102 | onInvalidRegistration?.({ |
| 103 | [getBetterAuthSignUpErrorField(res)]: res.error, |
| 104 | }); |
| 105 | return; |
| 106 | } |
| 107 |
no test coverage detected