import { useState } from 'react' import { supabase } from 'lib/Store' const Home = () => { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const handleLogin = async (type, username, password) => { try { const { error, data: { user } } = type === 'LOGIN' ? await supabase.auth.signInWithPassword({ email: username, password }) : await supabase.auth.signUp({ email: username, password }) // If the user doesn't exist here and an error hasn't been raised yet, // that must mean that a confirmation email has been sent. // NOTE: Confirming your email address is required by default. if (error) { alert('Error with auth: ' + error.message) } else if (!user) alert('Signup successful, confirmation mail should be sent soon!') } catch (error) { console.log('error', error) alert(error.error_description || error) } } return (
setUsername(e.target.value)} />
setPassword(e.target.value)} />
{ e.preventDefault() handleLogin('SIGNUP', username, password) }} href={'/channels'} className="bg-indigo-700 hover:bg-teal text-white py-2 px-4 rounded text-center transition duration-150 hover:bg-indigo-600 hover:text-white" > Sign up { e.preventDefault() handleLogin('LOGIN', username, password) }} href={'/channels'} className="border border-indigo-700 text-indigo-700 py-2 px-4 rounded w-full text-center transition duration-150 hover:bg-indigo-700 hover:text-white" > Login
) } export default Home