-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48ee8d6
commit 1536b6d
Showing
7 changed files
with
263 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,74 @@ | ||
import { View } from 'react-native'; | ||
import Account from '../../components/Account'; | ||
import Login from '../../components/Login'; | ||
import React, { useState } from 'react'; | ||
import { Redirect, Link } from 'expo-router'; | ||
import { Alert, StyleSheet, View } from 'react-native'; | ||
import { useSession } from '../../utils/AuthContext'; | ||
import { Button, Input } from 'react-native-elements'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginTop: 40, | ||
padding: 12, | ||
}, | ||
verticallySpaced: { | ||
paddingTop: 4, | ||
paddingBottom: 4, | ||
alignSelf: 'stretch', | ||
}, | ||
mt20: { | ||
marginTop: 20, | ||
}, | ||
}); | ||
|
||
function SignUpScreen() { | ||
const { session } = useSession(); | ||
const sessionHandler = useSession(); | ||
|
||
if (sessionHandler.session) { | ||
return <Redirect href={'/home'} />; | ||
} | ||
|
||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const signUpWithEmail = async () => { | ||
setLoading(true); | ||
const { error } = await sessionHandler.signUp(email, password); | ||
|
||
if (error) Alert.alert(error.message); | ||
else | ||
Alert.alert( | ||
'Please follow the instructions in your email to verify your account', | ||
); | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<View> | ||
{session && session.user ? <Account key={session.user.id} /> : <Login />} | ||
<View style={styles.container}> | ||
<View style={[styles.verticallySpaced, styles.mt20]}> | ||
<Input | ||
label="Email" | ||
leftIcon={{ type: 'font-awesome', name: 'envelope' }} | ||
onChangeText={text => setEmail(text)} | ||
value={email} | ||
placeholder="[email protected]" | ||
autoCapitalize="none" | ||
/> | ||
</View> | ||
<View style={styles.verticallySpaced}> | ||
<Input | ||
label="Password" | ||
leftIcon={{ type: 'font-awesome', name: 'lock' }} | ||
onChangeText={text => setPassword(text)} | ||
value={password} | ||
secureTextEntry | ||
placeholder="Password" | ||
autoCapitalize="none" | ||
/> | ||
</View> | ||
<Link href={'/auth/login'}>Already have an account? Log In</Link> | ||
<View style={[styles.verticallySpaced, styles.mt20]}> | ||
<Button title="Sign up" disabled={loading} onPress={signUpWithEmail} /> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { Redirect } from 'expo-router'; | ||
import { useSession } from '../utils/AuthContext'; | ||
|
||
function StartPage() { | ||
return <Redirect href="/auth" />; | ||
const { session } = useSession(); | ||
|
||
if (!session) return <Redirect href="/auth/login" />; | ||
else return <Redirect href={'/home'} />; | ||
} | ||
|
||
export default StartPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.