The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import { Link, redirect, useFetcher, useSearchParams, type ActionFunctionArgs } from 'react-router'
import { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'
import { Button } from '@/registry/default/components/ui/button'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/registry/default/components/ui/card'
import { Input } from '@/registry/default/components/ui/input'
import { Label } from '@/registry/default/components/ui/label'
export const action = async ({ request }: ActionFunctionArgs) => {
const { supabase } = createClient(request)
const url = new URL(request.url)
const origin = url.origin
const formData = await request.formData()
const email = formData.get('email') as string
const password = formData.get('password') as string
const repeatPassword = formData.get('repeat-password') as string
if (!password) {
return {
error: 'Password is required',
}
}
if (password !== repeatPassword) {
return { error: 'Passwords do not match' }
}
const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/protected`,
},
})
if (error) {
return { error: error.message }
}
return redirect('/sign-up?success')
}
export default function SignUp() {
const fetcher = useFetcher<typeof action>()
let [searchParams] = useSearchParams()
const success = !!searchParams.has('success')
const error = fetcher.data?.error
const loading = fetcher.state === 'submitting'
return (
<div className="flex min-h-svh w-full items-center justify-center p-6 md:p-10">
<div className="w-full max-w-sm">
<div className="flex flex-col gap-6">
{success ? (
<Card>
<CardHeader>
<CardTitle className="font-medium text-lg tracking-normal">
Thank you for signing up!
</CardTitle>
<CardDescription>Check your email to confirm</CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
You've successfully signed up. Please check your email to confirm your
account before signing in.
</p>
</CardContent>
</Card>
) : (
<Card>
<CardHeader>
<CardTitle className="font-medium text-lg tracking-normal">Sign up</CardTitle>
<CardDescription>Create a new account</CardDescription>
</CardHeader>
<CardContent>
<fetcher.Form method="post">
<div className="flex flex-col gap-6">
<div className="grid gap-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
name="email"
type="email"
placeholder="[email protected]"
required
/>
</div>
<div className="grid gap-2">
<div className="flex items-center">
<Label htmlFor="password">Password</Label>
</div>
<Input id="password" name="password" type="password" required />
</div>
<div className="grid gap-2">
<div className="flex items-center">
<Label htmlFor="repeat-password">Repeat Password</Label>
</div>
<Input id="repeat-password" name="repeat-password" type="password" required />
</div>
{error && <p className="text-sm text-red-500">{error}</p>}
<Button type="submit" className="w-full" disabled={loading}>
{loading ? 'Creating an account...' : 'Sign up'}
</Button>
</div>
<div className="mt-4 text-center text-sm">
Already have an account?{' '}
<Link to="/login" className="underline underline-offset-4">
Sign in
</Link>
</div>
</fetcher.Form>
</CardContent>
</Card>
)}
</div>
</div>
</div>
)
}