import { supabase } from 'lib/Store' import { useEffect, useState } from 'react' const Home = () => { const [session, setSession] = useState(null) const [mode, setMode] = useState('sign-in') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const [message, setMessage] = useState(null) useEffect(() => { supabase.auth.getSession().then(({ data: { session } }) => { setSession(session) }) const { data: { subscription }, } = supabase.auth.onAuthStateChange((_event, session) => { setSession(session) }) return () => subscription.unsubscribe() }, []) const handleSubmit = async (event) => { event.preventDefault() setIsLoading(true) setError(null) setMessage(null) if (mode === 'sign-in') { const { error } = await supabase.auth.signInWithPassword({ email, password }) if (error) setError(error.message) } else { const { data, error } = await supabase.auth.signUp({ email, password, options: { emailRedirectTo: `${window.location.origin}/` }, }) if (error) { setError(error.message) } else if (data.user && !data.session) { setMessage('Check your email for a confirmation link to complete sign up.') } } setIsLoading(false) } const handleGitHubSignIn = async () => { setIsLoading(true) setError(null) const { error } = await supabase.auth.signInWithOAuth({ provider: 'github', options: { redirectTo: `${window.location.origin}/` }, }) if (error) setError(error.message) setIsLoading(false) } if (!session) { return (
{error}
} {message &&{message}
}