'use client' import { useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { signUp } from '@/lib/actions/auth' import { useAuthCapabilities } from '@/lib/contexts/app-user-context' import { cn } from '@/lib/utils/index' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { IconLogo } from '@/components/ui/icons' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { PasswordInput } from '@/components/ui/password-input' export function SignUpForm({ className, token, inviteEmail, ...props }: React.ComponentPropsWithoutRef<'div'> & { token?: string inviteEmail?: string }) { const [email, setEmail] = useState(inviteEmail ?? '') const [password, setPassword] = useState('') const [repeatPassword, setRepeatPassword] = useState('') const [error, setError] = useState(null) const [notice, setNotice] = useState(null) const [isLoading, setIsLoading] = useState(false) const router = useRouter() const capabilities = useAuthCapabilities() const handleSignUp = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) setNotice(null) if (password !== repeatPassword) { setError('Passwords do not match') setIsLoading(false) return } try { const result = await signUp({ email, password, token }) if (!result.success) throw new Error(result.error ?? 'An error occurred') if (result.notice) { // Sign-up continues out-of-band (e.g. an emailed bootstrap link); // show the message instead of redirecting. setNotice(result.notice) return } if (capabilities.emailVerification) { router.push('/auth/sign-up-success') } else { // Providers without email verification sign the user in immediately; // send them straight to the app instead of a confirmation notice. router.push('/') router.refresh() } } catch (error: unknown) { setError(error instanceof Error ? error.message : 'An error occurred') } finally { setIsLoading(false) } } return (
Create an account Enter your details below to get started
setEmail(e.target.value)} /> {inviteEmail && (

This invitation is bound to {inviteEmail}.

)}
setPassword(e.target.value)} />
setRepeatPassword(e.target.value)} />
{error &&

{error}

} {notice &&

{notice}

}
Already have an account?{' '} Sign In
← Back to Home
) }