mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
8f08df1600
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Clarified React Native and Angular auth guides with improved environment setup and JWT validation guidance. * **New Features** * Added a React Native environment template for quickstart. * Example app now uses JWT claims for user state and display. * **Chores** * Replaced UI library components with native React Native components for compatibility. * Updated package configuration and dependency versions. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
122 lines
2.9 KiB
TypeScript
122 lines
2.9 KiB
TypeScript
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 (
|
|
<View style={styles.container}>
|
|
<View style={[styles.verticallySpaced, styles.mt20]}>
|
|
<Text style={styles.label}>Email</Text>
|
|
<TextInput
|
|
onChangeText={(text) => setEmail(text)}
|
|
value={email}
|
|
placeholder="email@address.com"
|
|
autoCapitalize="none"
|
|
style={styles.input}
|
|
/>
|
|
</View>
|
|
<View style={styles.verticallySpaced}>
|
|
<Text style={styles.label}>Password</Text>
|
|
<TextInput
|
|
onChangeText={(text) => setPassword(text)}
|
|
value={password}
|
|
secureTextEntry={true}
|
|
placeholder="Password"
|
|
autoCapitalize="none"
|
|
style={styles.input}
|
|
/>
|
|
</View>
|
|
<View style={[styles.verticallySpaced, styles.mt20]}>
|
|
<TouchableOpacity
|
|
style={[styles.button, loading && styles.buttonDisabled]}
|
|
onPress={() => signInWithEmail()}
|
|
disabled={loading}
|
|
>
|
|
<Text style={styles.buttonText}>Sign in</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
<View style={styles.verticallySpaced}>
|
|
<TouchableOpacity
|
|
style={[styles.button, loading && styles.buttonDisabled]}
|
|
onPress={() => signUpWithEmail()}
|
|
disabled={loading}
|
|
>
|
|
<Text style={styles.buttonText}>Sign up</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
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',
|
|
},
|
|
})
|