diff --git a/frontend/src/auth/SignIn.tsx b/frontend/src/auth/SignIn.tsx new file mode 100644 index 0000000..946e007 --- /dev/null +++ b/frontend/src/auth/SignIn.tsx @@ -0,0 +1,70 @@ +import { useState, type FormEvent } from 'react'; +import { supabase } from '../lib/supabase'; + +type Mode = 'signIn' | 'signUp'; + +export function SignIn() { + const [mode, setMode] = useState('signIn'); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(null); + const [busy, setBusy] = useState(false); + + async function onSubmit(e: FormEvent) { + e.preventDefault(); + setError(null); + setBusy(true); + try { + const { error } = + mode === 'signIn' + ? await supabase.auth.signInWithPassword({ email, password }) + : await supabase.auth.signUp({ email, password }); + if (error) setError(error.message); + // On success, AuthProvider's onAuthStateChange updates session and the UI switches. + } finally { + setBusy(false); + } + } + + return ( +
+

{mode === 'signIn' ? 'Sign in' : 'Sign up'}

+
+ + + +
+ {error &&

{error}

} +

+ +

+
+ ); +}