Skip to content

Commit

Permalink
Refactor handleSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciabad committed Oct 22, 2023
1 parent 040cc77 commit ddebc08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Input } from '@nextui-org/input'
import { IconEye, IconEyeOff } from '@tabler/icons-react'
import { signIn } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { FC, useState } from 'react'
import { FC, FormEvent, useState } from 'react'

export const ContinueWithEmail: FC<{
className?: string
Expand All @@ -16,11 +16,13 @@ export const ContinueWithEmail: FC<{
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')

const handleSubmit = async (e: FormEvent) => {
e.preventDefault()
await signIn('credentials', { email, password })
}

return (
<form
onSubmit={() => signIn('credentials', { email, password })}
className={className}
>
<form onSubmit={handleSubmit} className={className}>
<Input
label={t('inputs.email')}
variant="bordered"
Expand Down
8 changes: 4 additions & 4 deletions src/app/[locale]/register/_components/register-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Input } from '@nextui-org/input'
import { IconEye, IconEyeOff } from '@tabler/icons-react'
import { signIn } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { FC, useState } from 'react'
import { FC, FormEvent, useState } from 'react'
import { trpc } from '~/trpc'

export const RegisterForm: FC<{
Expand All @@ -20,12 +20,12 @@ export const RegisterForm: FC<{

const register = trpc.auth.register.useMutation()

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
const handleSubmit = async (e: FormEvent) => {
e.preventDefault()

register.mutate({ email, password, name })
await register.mutateAsync({ email, password, name })

signIn('credentials', {
await signIn('credentials', {
email,
password,
name,
Expand Down

0 comments on commit ddebc08

Please sign in to comment.