Skip to content

Commit

Permalink
Don't ask for name in register
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciabad committed Oct 22, 2023
1 parent 58327c6 commit 5f77acb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
35 changes: 21 additions & 14 deletions src/app/[locale]/register/_components/register-form.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use client'

import { Button } from '@nextui-org/button'
import { Checkbox } from '@nextui-org/checkbox'
import { Input } from '@nextui-org/input'
import { Link as NextUILink } from '@nextui-org/link'
import { IconEye, IconEyeOff } from '@tabler/icons-react'
import { signIn } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import Link from 'next-intl/link'
import { FC, FormEvent, useState } from 'react'
import { cn } from '~/helpers/cn'
import { trpc } from '~/trpc'

export const RegisterForm: FC<{
Expand All @@ -16,25 +20,23 @@ export const RegisterForm: FC<{
const toggleVisibility = () => setIsVisible(!isVisible)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [name, setName] = useState('')

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

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

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

await signIn('credentials', {
email,
password,
name,
callbackUrl: '/profile',
})
}

return (
<form onSubmit={handleSubmit} className={className}>
<form onSubmit={handleSubmit} className={cn('py-4', className)}>
<Input
label={t('inputs.email')}
variant="bordered"
Expand Down Expand Up @@ -71,16 +73,21 @@ export const RegisterForm: FC<{
type={isVisible ? 'text' : 'password'}
/>

<Input
label={t('inputs.name')}
variant="bordered"
labelPlacement="outside"
placeholder={t('inputs.name-placeholder')}
isRequired
type="text"
value={name}
onValueChange={setName}
/>
<Checkbox isRequired className="mt-4">
{t.rich('inputs.terms-of-service', {
link: (text) => (
<NextUILink
as={Link}
href="/support/terms-of-service"
underline="always"
isExternal
showAnchorIcon
>
{text}
</NextUILink>
),
})}
</Checkbox>

{register.error && (
<p className="mt-8 text-danger-700">{register.error.message}</p>
Expand Down
3 changes: 2 additions & 1 deletion src/messages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"password": "Contrasenya",
"password-placeholder": "Introdueix la teva contrasenya",
"name": "Nom",
"name-placeholder": "Introdueix el teu nom"
"name-placeholder": "Introdueix el teu nom",
"terms-of-service": "Accepto els <link>termes del servei</link>."
}
},
"language-switcher": {
Expand Down
3 changes: 2 additions & 1 deletion src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"password-placeholder": "Enter your password",
"password-invalid": "Password is invalid",
"name": "Name",
"name-placeholder": "Enter your name"
"name-placeholder": "Enter your name",
"terms-of-service": "I accept the <link>terms of service</link>."
}
},
"language-switcher": {
Expand Down
1 change: 0 additions & 1 deletion src/schemas/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const loginSchema = z.object({
export const registerSchema = z.object({
email: z.string().email(),
password: passwordSchema,
name: z.string().min(1),
})

export type LoginSchemaType = z.infer<typeof loginSchema>
Expand Down
1 change: 0 additions & 1 deletion src/server/api/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const authRouter = router({
id: uuidv4(),
email: input.email,
hashedPassword: bcrypt.hashSync(input.password, 10),
name: input.name,
})
}),
})

0 comments on commit 5f77acb

Please sign in to comment.