import { useState, type FormEvent } from 'react'
import { Link, useNavigate } from '@tanstack/react-router'
import { AuthCard } from '@/components/auth/AuthCard'
import { Alert } from '@/components/ui/Alert'
import { Button } from '@/components/ui/Button'
import { TextField } from '@/components/ui/TextField'
import { apiErrorCode, errorMessage } from '@/lib/api'
import { useProviders, useRegister } from '@/lib/auth'
const MIN_PASSWORD = 8
export function RegisterPage() {
const navigate = useNavigate()
const providers = useProviders()
const register = useRegister()
const [email, setEmail] = useState('')
const [displayName, setDisplayName] = useState('')
const [password, setPassword] = useState('')
async function onSubmit(e: FormEvent) {
e.preventDefault()
try {
await register.mutateAsync({ email, displayName, password })
await navigate({ to: '/gardens' }) // registration auto-logs-in
} catch {
// Shown below via register.error.
}
}
// Don't render the form until we know local registration is offered — otherwise
// it briefly appears (and is submittable) on an SSO-only server.
if (providers.isPending) {
return (
Loading…
)
}
if (providers.isError) {
return (
Could not load sign-in options. Please refresh.
)
}
// Local registration is only meaningful when local auth is enabled.
if (!providers.data.local) {
return (
This server uses single sign-on. Local registration is disabled.
Back to sign in