Skip to content

Commit

Permalink
fix: have sign up emit errors as well
Browse files Browse the repository at this point in the history
  • Loading branch information
torrance-stripe committed Oct 23, 2024
1 parent 7b7c237 commit 17cb4b7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/(auth)/signup/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ export default function SignupForm() {

const onSubmit = async (values: z.infer<typeof formSchema>) => {
try {
await signIn('signup', {
const result = await signIn('signup', {
email: values.email,
password: values.password,
redirect: false,
});

router.push('/business');
if (result?.error) {
// Just assume the error is because the email is already in use
form.setError('root', {
type: 'manual',
message: 'The email is already in use.',
});
} else if (result?.ok) {
router.push('/business');
}
} catch (error: any) {
console.error('An error occurred when signing in', error);
}
Expand Down Expand Up @@ -106,6 +114,11 @@ export default function SignupForm() {
</div>
)}
</Button>
{form.formState.errors.root && (
<p className="text-sm text-red-500">
{form.formState.errors.root.message}
</p>
)}
</form>
</Form>
);
Expand Down

0 comments on commit 17cb4b7

Please sign in to comment.