Password Based Auth flow for React and Supabase
supabase-library/password-based-auth-reactFreeBlock
Password Based Auth flow for React and Supabase
Install it
npx shadcn@latest add https://raw.githubusercontent.com/supabase/supabase/master/apps/ui-library/public/r/password-based-auth-react.jsonSource
1import { useState } from 'react'23import { cn } from '@/lib/utils'4import { createClient } from '@/registry/default/clients/react/lib/supabase/client'5import { Button } from '@/registry/default/components/ui/button'6import {7 Card,8 CardContent,9 CardDescription,10 CardHeader,11 CardTitle,12} from '@/registry/default/components/ui/card'13import { Input } from '@/registry/default/components/ui/input'14import { Label } from '@/registry/default/components/ui/label'1516export function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {17 const [email, setEmail] = useState('')18 const [password, setPassword] = useState('')19 const [error, setError] = useState<string | null>(null)20 const [isLoading, setIsLoading] = useState(false)21 const supabase = createClient()2223 const handleLogin = async (e: React.FormEvent) => {24 e.preventDefault()25 setIsLoading(true)26 setError(null)2728 try {29 const { error } = await supabase.auth.signInWithPassword({30 email,31 password,32 })33 if (error) throw error34 // Update this route to redirect to an authenticated route. The user already has an active session.35 location.href = '/protected'36 } catch (error: unknown) {37 setError(error instanceof Error ? error.message : 'An error occurred')38 } finally {39 setIsLoading(false)40 }41 }4243 return (44 <div className={cn('flex flex-col gap-6', className)} {...props}>45 <Card>46 <CardHeader>47 <CardTitle className="text-2xl">Login</CardTitle>48 <CardDescription>Enter your email below to login to your account</CardDescription>49 </CardHeader>50 <CardContent>51 <form onSubmit={handleLogin}>52 <div className="flex flex-col gap-6">53 <div className="grid gap-2">54 <Label htmlFor="email">Email</Label>55 <Input56 id="email"57 type="email"58 placeholder="m@example.com"59 required60 value={email}61 onChange={(e) => setEmail(e.target.value)}62 />63 </div>64 <div className="grid gap-2">65 <div className="flex items-center">66 <Label htmlFor="password">Password</Label>67 <a68 href="/forgot-password"69 className="ml-auto inline-block text-sm underline-offset-4 hover:underline"70 >71// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Supabase Library
All 60 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Current User Avatarcurrent-user-avatar-nuxtjs | Supabase Library | Blocks | Free | 1 dep · 3 files | |
| Current User Avatarcurrent-user-avatar-vue | Supabase Library | Blocks | Free | 1 dep · 3 files | |
| Dropzone (File Upload) for Nuxt and Supabasedropzone-nuxtjs | Supabase Library | Blocks | Free | 3 deps · 4 files | |
| Dropzone (File Upload) for Vue and Supabasedropzone-vue | Supabase Library | Blocks | Free | 3 deps · 4 files | |
| Infinite Query Hookinfinite-query-hook | Supabase Library | Blocks | Free | 2 deps | |
| Password Based Auth flow for Nextjs and Supabasepassword-based-auth-nextjs | Supabase Library | Blocks | Free | 2 deps · 17 files | |
| Password Based Auth flow for Nuxt.js and Supabasepassword-based-auth-nuxtjs | Supabase Library | Blocks | Free | 2 deps · 12 files | |
| Password Based Auth flow for React Router and Supabasepassword-based-auth-react-router | Supabase Library | Blocks | Free | 4 deps · 11 files |
