Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 92 additions & 38 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { Logo } from '@/components/logo'
import { Button } from '@/components/ui/button'
import { signUp } from '@/features/auth/actions'
import { supabase } from '@/lib/supabase/client'
import { ArrowRight, Loader2 } from 'lucide-react'
Expand Down Expand Up @@ -34,8 +35,9 @@ function LoginForm() {
const [busy, setBusy] = useState(false)
const [error, setError] = useState<string | null>(null)
const [notice, setNotice] = useState<string | null>(null)
const [loadingOAuth, setLoadingOAuth] = useState(false)

async function submit(e: React.FormEvent) {
async function submit(e: React.SubmitEvent) {
e.preventDefault()
if (busy) return
setBusy(true)
Expand All @@ -62,6 +64,24 @@ function LoginForm() {
}
}

async function signInWithGithub() {
setLoadingOAuth(true)
try {
const { error } = await supabase.auth.signInWithOAuth({
provider: 'github',
})
if (error) throw error
router.replace(explicitNext || '/onboarding')
} catch (err) {
setError(
err instanceof Error
? err.message
: 'Falha na autenticação GitHub OAuth',
)
setLoadingOAuth(false)
}
}

return (
<div className='relative flex min-h-screen flex-1 flex-col bg-white'>
<header className='flex h-16 shrink-0 items-center px-6 sm:px-10'>
Expand All @@ -84,43 +104,77 @@ function LoginForm() {
: 'Leva 30 segundos. Sem cartão.'}
</p>

<form onSubmit={submit} className='flex flex-col gap-3'>
<input
type='email'
required
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder='seu@email.com'
className='rounded-xl border border-[#DFE5E9] bg-white px-4 py-3 text-[#1b1916] outline-none focus:border-primary/50 focus:ring-2 focus:ring-primary/20'
/>
<input
type='password'
required
minLength={6}
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder='senha (mín. 6 caracteres)'
className='rounded-xl border border-[#DFE5E9] bg-white px-4 py-3 text-[#1b1916] outline-none focus:border-primary/50 focus:ring-2 focus:ring-primary/20'
/>

{error && <p className='text-sm text-[#c0392b]'>{error}</p>}
{notice && <p className='text-sm text-[#6b6478]'>{notice}</p>}
<div className='flex flex-col gap-6'>
<div className='flex flex-col gap-3'>
<Button
onClick={signInWithGithub}
variant='outline'
size='lg'
loading={loadingOAuth}
className='rounded-xl [&_svg]:size-5!'
>
{!loadingOAuth && (
<svg
className='fill-foreground'
width='24'
height='24'
viewBox='0 0 1024 1024'
xmlns='http://www.w3.org/2000/svg'
>
<path
fillRule='evenodd'
clipRule='evenodd'
d='M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z'
transform='scale(64)'
></path>
</svg>
)}
Entrar com GitHub
</Button>
{error && <p className='text-sm text-[#c0392b]'>{error}</p>}
</div>
<div className='flex items-center gap-2 text-muted-foreground'>
<div className='h-px flex-1 bg-input' />
<span>ou</span>
<div className='h-px flex-1 bg-input' />
</div>

<button
type='submit'
disabled={busy}
className='group mt-2 inline-flex items-center justify-center gap-2 rounded-xl bg-primary px-6 py-3.5 text-base font-medium tracking-tight text-primary-foreground transition-colors duration-300 hover:bg-primary/90 disabled:opacity-50'
>
{busy ? (
<Loader2 className='size-4 animate-spin' />
) : (
<>
{mode === 'login' ? 'Entrar' : 'Criar conta'}
<ArrowRight className='size-4 transition-transform group-hover:translate-x-0.5' />
</>
)}
</button>
</form>
<form onSubmit={submit} className='flex flex-col gap-3'>
<input
type='email'
required
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder='seu@email.com'
className='rounded-xl border border-[#DFE5E9] bg-white px-4 py-3 text-[#1b1916] outline-none focus:border-primary/50 focus:ring-2 focus:ring-primary/20'
/>
<input
type='password'
required
minLength={6}
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder='senha (mín. 6 caracteres)'
className='rounded-xl border border-[#DFE5E9] bg-white px-4 py-3 text-[#1b1916] outline-none focus:border-primary/50 focus:ring-2 focus:ring-primary/20'
/>
{error && <p className='text-sm text-[#c0392b]'>{error}</p>}
{notice && <p className='text-sm text-[#6b6478]'>{notice}</p>}
<button
type='submit'
disabled={busy}
className='group mt-2 inline-flex cursor-pointer items-center justify-center gap-2 rounded-xl bg-primary px-6 py-3.5 text-base font-medium tracking-tight text-primary-foreground transition-colors duration-300 hover:bg-primary/90 disabled:opacity-50'
>
{busy ? (
<Loader2 className='size-4 animate-spin' />
) : (
<>
{mode === 'login' ? 'Entrar' : 'Criar conta'}
<ArrowRight className='size-4 transition-transform group-hover:translate-x-0.5' />
</>
)}
</button>
</form>
</div>

<button
type='button'
Expand All @@ -129,7 +183,7 @@ function LoginForm() {
setError(null)
setNotice(null)
}}
className='mt-5 text-sm text-[#6b6478] transition-colors hover:text-[#1b1916]'
className='mt-5 cursor-pointer text-sm text-[#6b6478] transition-colors hover:text-[#1b1916]'
>
{mode === 'login'
? 'Não tem conta? Criar uma'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const buttonVariants = cva(
"size-11 sm:size-10 [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-4.5",
'icon-xs':
"size-7 rounded-md before:rounded-[calc(var(--radius-md)-1px)] sm:size-6 not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-4 sm:not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-3.5",
lg: 'h-10 px-[calc(--spacing(3.5)-1px)] sm:h-9',
lg: 'h-auto px-4 py-3 text-base! gap-3',
sm: 'h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:h-7',
xl: "h-11 px-[calc(--spacing(4)-1px)] text-lg sm:h-10 sm:text-base [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-4.5",
xs: "h-7 gap-1 rounded-md px-[calc(--spacing(2)-1px)] text-sm before:rounded-[calc(var(--radius-md)-1px)] sm:h-6 sm:text-xs [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5",
Expand Down
Loading