import React, { useState } from 'react' import { Alert, StyleSheet, View, Text, TextInput, TouchableOpacity } from 'react-native' import { supabase } from '../lib/supabase' export default function Auth() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) async function signInWithEmail() { setLoading(true) const { error } = await supabase.auth.signInWithPassword({ email: email, password: password, }) if (error) Alert.alert(error.message) setLoading(false) } async function signUpWithEmail() { setLoading(true) const { data: { session }, error, } = await supabase.auth.signUp({ email: email, password: password, }) if (error) Alert.alert(error.message) if (!session) Alert.alert('Please check your inbox for email verification!') setLoading(false) } return ( Email setEmail(text)} value={email} placeholder="email@address.com" autoCapitalize="none" style={styles.input} /> Password setPassword(text)} value={password} secureTextEntry={true} placeholder="Password" autoCapitalize="none" style={styles.input} /> signInWithEmail()} disabled={loading} > Sign in signUpWithEmail()} disabled={loading} > Sign up ) } const styles = StyleSheet.create({ container: { marginTop: 40, padding: 12, }, verticallySpaced: { paddingTop: 4, paddingBottom: 4, alignSelf: 'stretch', }, mt20: { marginTop: 20, }, label: { fontSize: 16, fontWeight: '600', color: '#86939e', marginBottom: 6, }, input: { borderWidth: 1, borderColor: '#86939e', borderRadius: 4, padding: 12, fontSize: 16, }, button: { backgroundColor: '#2089dc', borderRadius: 4, padding: 12, alignItems: 'center', }, buttonDisabled: { opacity: 0.5, }, buttonText: { color: '#fff', fontSize: 16, fontWeight: '600', }, })