diff --git a/src/app/auth/_layout.tsx b/src/app/auth/_layout.tsx
index 0578a39c..cf7d8349 100644
--- a/src/app/auth/_layout.tsx
+++ b/src/app/auth/_layout.tsx
@@ -5,6 +5,7 @@ function StackLayout() {
+
);
diff --git a/src/components/Login.tsx b/src/app/auth/login.tsx
similarity index 73%
rename from src/components/Login.tsx
rename to src/app/auth/login.tsx
index 4868fe27..aa1cb78b 100644
--- a/src/components/Login.tsx
+++ b/src/app/auth/login.tsx
@@ -1,7 +1,9 @@
import React, { useState } from 'react';
+import { Redirect } from 'expo-router';
import { Alert, StyleSheet, View } from 'react-native';
+import { useSession } from '../../utils/AuthContext';
import { Button, Input } from 'react-native-elements';
-import { useSession } from '../utils/AuthContext';
+import { Link } from 'expo-router';
const styles = StyleSheet.create({
container: {
@@ -18,8 +20,13 @@ const styles = StyleSheet.create({
},
});
-export default function Login() {
+function LoginScreen() {
const sessionHandler = useSession();
+
+ if (sessionHandler.session) {
+ return ;
+ }
+
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
@@ -32,21 +39,6 @@ export default function Login() {
setLoading(false);
};
- const signUpWithEmail = async () => {
- setLoading(true);
- const { error } = await sessionHandler.signUp(email, password);
-
- if (error) {
- Alert.alert(error.message);
- console.error(error);
- } else {
- Alert.alert(
- 'Please follow the directions in the confirmation email to activate your account.',
- );
- }
- setLoading(false);
- };
-
return (
@@ -70,12 +62,14 @@ export default function Login() {
autoCapitalize="none"
/>
+
+ Don't have an account? Sign up
+
-
-
-
);
}
+
+export default LoginScreen;
diff --git a/src/app/auth/onboarding.tsx b/src/app/auth/onboarding.tsx
index 2f0f643d..72189398 100644
--- a/src/app/auth/onboarding.tsx
+++ b/src/app/auth/onboarding.tsx
@@ -1,15 +1,175 @@
-import { View } from 'react-native';
-import Login from '../../components/Login';
-import Account from '../../components/Account';
+import { useState, useEffect } from 'react';
+import { StyleSheet, View, Alert, ScrollView, Platform } from 'react-native';
+import { Button, Input } from 'react-native-elements';
+import DateTimePicker from '@react-native-community/datetimepicker';
+import supabase from '../../utils/supabase';
+import UserStringInput from '../../components/UserStringInput';
import { useSession } from '../../utils/AuthContext';
+import { Redirect } from 'expo-router';
+
+const styles = StyleSheet.create({
+ container: {
+ marginTop: 40,
+ padding: 12,
+ },
+ verticallySpaced: {
+ paddingTop: 4,
+ paddingBottom: 4,
+ alignSelf: 'stretch',
+ },
+ mt20: {
+ marginTop: 20,
+ },
+});
function OnboardingScreen() {
- const { session } = useSession();
+ const { session, signOut } = useSession();
+
+ if (!session) {
+ return ;
+ }
+
+ const [loading, setLoading] = useState(true);
+ const [firstName, setFirstName] = useState('');
+ const [lastName, setLastName] = useState('');
+ const [birthday, setBirthday] = useState(new Date());
+ const [gender, setGender] = useState('');
+ const [raceEthnicity, setRaceEthnicity] = useState('');
+ const [showDatePicker, setShowDatePicker] = useState(Platform.OS === 'ios');
+
+ const getProfile = async () => {
+ try {
+ setLoading(true);
+ if (!session?.user) throw new Error('No user on the session!');
+
+ const { data, error, status } = await supabase
+ .from('profiles')
+ .select(`first_name, last_name, birthday, gender, race_ethnicity`)
+ .eq('user_id', session?.user.id)
+ .single();
+
+ if (error && status !== 406) {
+ throw error;
+ }
+
+ if (data) {
+ setFirstName(data.first_name || firstName);
+ setLastName(data.last_name || lastName);
+ setBirthday(new Date(data.birthday) || birthday);
+ setGender(data.gender || gender);
+ setRaceEthnicity(data.race_ethnicity || raceEthnicity);
+ }
+ } catch (error) {
+ if (error instanceof Error) {
+ Alert.alert(`Get profile error: ${error.message}`);
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ if (session) getProfile();
+ }, [session]);
+
+ const updateProfile = async () => {
+ try {
+ setLoading(true);
+ if (!session?.user) throw new Error('No user on the session!');
+
+ // Only update values that are not blank
+ const updates = {
+ ...(firstName && { first_name: firstName }),
+ ...(lastName && { last_name: lastName }),
+ ...(gender && { gender }),
+ ...(raceEthnicity && { race_ethnicity: raceEthnicity }),
+ ...(birthday && { birthday }),
+ };
+
+ // Check if user exists
+ const { count } = await supabase
+ .from('profiles')
+ .select(`*`, { count: 'exact' })
+ .eq('user_id', session?.user.id);
+
+ if (count && count >= 1) {
+ // Update user if they exist
+ const { error } = await supabase
+ .from('profiles')
+ .update(updates)
+ .eq('user_id', session?.user.id)
+ .select('*');
+
+ if (error) throw error;
+ } else {
+ // Create user if they don't exist
+ const { error } = await supabase.from('profiles').insert(updates);
+
+ if (error) throw error;
+ }
+
+ Alert.alert('Succesfully updated user!');
+ } catch (error) {
+ if (error instanceof Error) {
+ Alert.alert(error.message);
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
return (
-
- {session && session.user ? : }
-
+
+
+
+
+
+
+
+
+
+ {Platform.OS !== 'ios' && (
+
);
}
diff --git a/src/app/auth/signup.tsx b/src/app/auth/signup.tsx
index 8072d3c9..c5c8e246 100644
--- a/src/app/auth/signup.tsx
+++ b/src/app/auth/signup.tsx
@@ -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 ;
+ }
+
+ 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 (
-
- {session && session.user ? : }
+
+
+ setEmail(text)}
+ value={email}
+ placeholder="email@address.com"
+ autoCapitalize="none"
+ />
+
+
+ setPassword(text)}
+ value={password}
+ secureTextEntry
+ placeholder="Password"
+ autoCapitalize="none"
+ />
+
+ Already have an account? Log In
+
+
+
);
}
diff --git a/src/app/index.tsx b/src/app/index.tsx
index 91b8d926..8280abec 100644
--- a/src/app/index.tsx
+++ b/src/app/index.tsx
@@ -1,7 +1,11 @@
import { Redirect } from 'expo-router';
+import { useSession } from '../utils/AuthContext';
function StartPage() {
- return ;
+ const { session } = useSession();
+
+ if (!session) return ;
+ else return ;
}
export default StartPage;
diff --git a/src/app/settings.tsx b/src/app/settings.tsx
index a2735d99..8e5d7b20 100644
--- a/src/app/settings.tsx
+++ b/src/app/settings.tsx
@@ -1,11 +1,20 @@
-import { Text } from 'react-native';
+import { Redirect } from 'expo-router';
+import { Text, View } from 'react-native';
+import { Button } from 'react-native-elements';
import { SafeAreaView } from 'react-native-safe-area-context';
import globalStyles from '../../globalStyles';
+import { useSession } from '../utils/AuthContext';
function SettingsScreen() {
+ const { session, signOut } = useSession();
+
+ if (!session) return ;
return (
Settings
+
+
+
);
}
diff --git a/src/components/Account.tsx b/src/components/Account.tsx
deleted file mode 100644
index ebe214f1..00000000
--- a/src/components/Account.tsx
+++ /dev/null
@@ -1,169 +0,0 @@
-import { useState, useEffect } from 'react';
-import { StyleSheet, View, Alert, ScrollView, Platform } from 'react-native';
-import { Button, Input } from 'react-native-elements';
-import DateTimePicker from '@react-native-community/datetimepicker';
-import supabase from '../utils/supabase';
-import UserStringInput from './UserStringInput';
-import { useSession } from '../utils/AuthContext';
-
-const styles = StyleSheet.create({
- container: {
- marginTop: 40,
- padding: 12,
- },
- verticallySpaced: {
- paddingTop: 4,
- paddingBottom: 4,
- alignSelf: 'stretch',
- },
- mt20: {
- marginTop: 20,
- },
-});
-
-export default function Account() {
- const { session, signOut } = useSession();
-
- const [loading, setLoading] = useState(true);
- const [firstName, setFirstName] = useState('');
- const [lastName, setLastName] = useState('');
- const [birthday, setBirthday] = useState(new Date());
- const [gender, setGender] = useState('');
- const [raceEthnicity, setRaceEthnicity] = useState('');
- const [showDatePicker, setShowDatePicker] = useState(Platform.OS === 'ios');
-
- const getProfile = async () => {
- try {
- setLoading(true);
- if (!session?.user) throw new Error('No user on the session!');
-
- const { data, error, status } = await supabase
- .from('profiles')
- .select(`first_name, last_name, birthday, gender, race_ethnicity`)
- .eq('user_id', session?.user.id)
- .single();
-
- if (error && status !== 406) {
- throw error;
- }
-
- if (data) {
- setFirstName(data.first_name || firstName);
- setLastName(data.last_name || lastName);
- setBirthday(new Date(data.birthday) || birthday);
- setGender(data.gender || gender);
- setRaceEthnicity(data.race_ethnicity || raceEthnicity);
- }
- } catch (error) {
- if (error instanceof Error) {
- Alert.alert(`Get profile error: ${error.message}`);
- }
- } finally {
- setLoading(false);
- }
- };
-
- useEffect(() => {
- if (session) getProfile();
- }, [session]);
-
- const updateProfile = async () => {
- try {
- setLoading(true);
- if (!session?.user) throw new Error('No user on the session!');
-
- // Only update values that are not blank
- const updates = {
- ...(firstName && { first_name: firstName }),
- ...(lastName && { last_name: lastName }),
- ...(gender && { gender }),
- ...(raceEthnicity && { race_ethnicity: raceEthnicity }),
- ...(birthday && { birthday }),
- };
-
- // Check if user exists
- const { count } = await supabase
- .from('profiles')
- .select(`*`, { count: 'exact' })
- .eq('user_id', session?.user.id);
-
- if (count && count >= 1) {
- // Update user if they exist
- const { error } = await supabase
- .from('profiles')
- .update(updates)
- .eq('user_id', session?.user.id)
- .select('*');
-
- if (error) throw error;
- } else {
- // Create user if they don't exist
- const { error } = await supabase.from('profiles').insert(updates);
-
- if (error) throw error;
- }
-
- Alert.alert('Succesfully updated user!');
- } catch (error) {
- if (error instanceof Error) {
- Alert.alert(error.message);
- }
- } finally {
- setLoading(false);
- }
- };
-
- return (
-
-
-
-
-
-
-
-
-
- {Platform.OS !== 'ios' && (
- setShowDatePicker(true)}
- />
- )}
- {showDatePicker && (
- {
- setShowDatePicker(Platform.OS === 'ios');
- if (date.nativeEvent.timestamp) {
- setBirthday(new Date(date.nativeEvent.timestamp));
- }
- }}
- />
- )}
-
-
-
-
-
-
-
- );
-}