-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: email and password length validation on backend
- Loading branch information
1 parent
ebf0f8a
commit d81c77d
Showing
5 changed files
with
112 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import vine from '@vinejs/vine' | ||
import { VineValidationError } from '../../types/validation.js' | ||
|
||
export const createUserValidator = vine.compile( | ||
vine.object({ | ||
email: vine.string().email(), | ||
password: vine.string().minLength(8).confirmed(), | ||
}) | ||
) | ||
|
||
export const createUserValidatorErrorMessage = (error: VineValidationError) => { | ||
const rule = error.messages[0].rule | ||
|
||
switch (rule) { | ||
case 'email': | ||
return 'E-mail inválido' | ||
case 'minLength': | ||
return 'Palavra-passe tem de ter no mínimo 8 caratéres' | ||
case 'confirmed': | ||
return 'Palavras-passe não coincidem' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { Link } from '@tuyau/inertia/react' | ||
import { Button, buttonVariants } from '~/components/ui/button' | ||
import { Button } from '~/components/ui/button' | ||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '~/components/ui/card' | ||
import { Input } from '~/components/ui/input' | ||
import { Label } from '~/components/ui/label' | ||
import { Separator } from '~/components/ui/separator' | ||
import { useError } from '~/hooks/use_error' | ||
import { useForm } from '@inertiajs/react' | ||
import { cn } from '~/lib/utils' | ||
|
@@ -28,7 +26,7 @@ export default function Login() { | |
<AppLayout title="Criar conta"> | ||
<div className="flex items-center justify-center w-full mt-24"> | ||
<div className="flex flex-col gap-6 max-w-sm"> | ||
<Card className={cn(oauthError && 'border-red-600')}> | ||
<Card className={cn(oauthError && 'border-2 border-red-600')}> | ||
<CardHeader> | ||
<CardTitle className="text-2xl text-enei-blue">Criar conta</CardTitle> | ||
<CardDescription> | ||
|
@@ -42,7 +40,7 @@ export default function Login() { | |
<Label htmlFor="email">E-mail</Label> | ||
<Input | ||
id="email" | ||
type="email" | ||
type="text" | ||
placeholder="[email protected]" | ||
value={data.email} | ||
onChange={(e) => setData('email', e.target.value)} | ||
|
@@ -80,40 +78,40 @@ export default function Login() { | |
<Button type="submit" className="w-full bg-enei-blue"> | ||
Criar conta | ||
</Button> | ||
<div className="flex gap-2 items-center"> | ||
<Separator className="shrink" /> | ||
<p className="text-sm text-muted-foreground min-w-max">Ou</p> | ||
<Separator className="shrink" /> | ||
</div> | ||
<div className="grid grid-cols-3 gap-2"> | ||
<Link | ||
route="auth.google.initiate" | ||
className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} | ||
> | ||
<span className="sr-only">Iniciar Sessão com o</span> Google | ||
{/* <Google className="h-5 w-5" /> */} | ||
</Link> | ||
<Link | ||
route="auth.github.initiate" | ||
className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} | ||
> | ||
<span className="sr-only">Iniciar Sessão com o</span> Github | ||
{/* <Github className="h-5 w-5" /> */} | ||
</Link> | ||
<Link | ||
route="auth.linkedin.initiate" | ||
className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} | ||
> | ||
<span className="sr-only">Iniciar Sessão com o</span> LinkedIn | ||
{/* <LinkedIn className="h-5 w-5" /> */} | ||
</Link> | ||
</div> | ||
{/* <div className="flex gap-2 items-center"> */} | ||
{/* <Separator className="shrink" /> */} | ||
{/* <p className="text-sm text-muted-foreground min-w-max">Ou</p> */} | ||
{/* <Separator className="shrink" /> */} | ||
{/* </div> */} | ||
{/* <div className="grid grid-cols-3 gap-2"> */} | ||
{/* <Link */} | ||
{/* route="auth.google.initiate" */} | ||
{/* className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} */} | ||
{/* > */} | ||
{/* <span className="sr-only">Iniciar Sessão com o</span> Google */} | ||
{/* {/* <Google className="h-5 w-5" /> */} | ||
{/* </Link> */} | ||
{/* <Link */} | ||
{/* route="auth.github.initiate" */} | ||
{/* className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} */} | ||
{/* > */} | ||
{/* <span className="sr-only">Iniciar Sessão com o</span> Github */} | ||
{/* {/* <Github className="h-5 w-5" /> */} | ||
{/* </Link> */} | ||
{/* <Link */} | ||
{/* route="auth.linkedin.initiate" */} | ||
{/* className={cn(buttonVariants({ variant: 'outline' }), 'w-full')} */} | ||
{/* > */} | ||
{/* <span className="sr-only">Iniciar Sessão com o</span> LinkedIn */} | ||
{/* {/* <LinkedIn className="h-5 w-5" /> */} | ||
{/* </Link> */} | ||
{/* </div> */} | ||
</div> | ||
</div> | ||
</form> | ||
{oauthError && <p className="text-sm text-red-600 text-center mt-4">{oauthError}</p>} | ||
</CardContent> | ||
</Card> | ||
{oauthError && <p className="text-sm text-red-600 text-center">{oauthError}</p>} | ||
</div> | ||
</div> | ||
</AppLayout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Types declared for error formats in the validators using vine | ||
*/ | ||
|
||
export type VineValidationError = { | ||
code: string | ||
messages: Array<VineValidationErrorMessage> | ||
} | ||
|
||
export type VineValidationErrorMessage = { | ||
rule: string | ||
message: string | ||
field: string | ||
} |