diff --git a/src/app/auth/index.tsx b/src/app/auth/index.tsx
index b33a3c23..22156936 100644
--- a/src/app/auth/index.tsx
+++ b/src/app/auth/index.tsx
@@ -8,8 +8,11 @@ function LoginScreen() {
return (
Auth
-
);
diff --git a/src/app/auth/login.tsx b/src/app/auth/login.tsx
index 4015aabd..e8039e51 100644
--- a/src/app/auth/login.tsx
+++ b/src/app/auth/login.tsx
@@ -1,9 +1,10 @@
+import { Link, router } from 'expo-router';
import React, { useState } from 'react';
-import { Redirect, Link } from 'expo-router';
import { Alert, View } from 'react-native';
import { Button, Input } from 'react-native-elements';
-import { useSession } from '../../utils/AuthContext';
+
import globalStyles from '../../styles/globalStyles';
+import { useSession } from '../../utils/AuthContext';
function LoginScreen() {
const sessionHandler = useSession();
@@ -11,21 +12,25 @@ function LoginScreen() {
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
- if (sessionHandler.session) {
- return ;
- }
+ const resetAndPushToRouter = (path: string) => {
+ while (router.canGoBack()) {
+ router.back();
+ }
+ router.replace(path);
+ };
const signInWithEmail = async () => {
setLoading(true);
- const { error, data } = await sessionHandler.signInWithEmail(
- email,
- password,
- );
+ const { error } = await sessionHandler.signInWithEmail(email, password);
if (error) Alert.alert(error.message);
setLoading(false);
};
+ if (sessionHandler.session) {
+ resetAndPushToRouter('/home');
+ }
+
return (
diff --git a/src/app/auth/onboarding.tsx b/src/app/auth/onboarding.tsx
index 78b16b02..7f3e914e 100644
--- a/src/app/auth/onboarding.tsx
+++ b/src/app/auth/onboarding.tsx
@@ -1,15 +1,16 @@
+import DateTimePicker from '@react-native-community/datetimepicker';
+import { Redirect, router } from 'expo-router';
import { useState, useEffect } from 'react';
import { View, Alert, ScrollView, Platform } from 'react-native';
import { Button, Input } from 'react-native-elements';
-import DateTimePicker from '@react-native-community/datetimepicker';
-import { Redirect, router } from 'expo-router';
-import supabase from '../../utils/supabase';
+
import UserStringInput from '../../components/UserStringInput';
-import { useSession } from '../../utils/AuthContext';
import globalStyles from '../../styles/globalStyles';
+import { useSession } from '../../utils/AuthContext';
+import supabase from '../../utils/supabase';
function OnboardingScreen() {
- const { session, signOut } = useSession();
+ const { session } = useSession();
const [loading, setLoading] = useState(true);
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
@@ -29,7 +30,7 @@ function OnboardingScreen() {
.eq('user_id', session?.user.id)
.single();
- if (error && status !== 406) {
+ if (error && status !== 406 && error instanceof Error) {
throw error;
}
@@ -81,12 +82,12 @@ function OnboardingScreen() {
.eq('user_id', session?.user.id)
.select('*');
- if (error) throw error;
+ if (error && error instanceof Error) throw error;
} else {
// Create user if they don't exist
const { error } = await supabase.from('profiles').insert(updates);
- if (error) throw error;
+ if (error && error instanceof Error) throw error;
}
Alert.alert('Succesfully updated user!');
@@ -153,7 +154,7 @@ function OnboardingScreen() {
/>
- router.push('/home')} />
+ router.replace('/home')} />
);
diff --git a/src/app/auth/signup.tsx b/src/app/auth/signup.tsx
index 94db3d4f..ca4e275b 100644
--- a/src/app/auth/signup.tsx
+++ b/src/app/auth/signup.tsx
@@ -1,9 +1,10 @@
-import React, { useEffect, useState } from 'react';
import { Redirect, Link, router } from 'expo-router';
-import { Alert, View, Text } from 'react-native';
+import React, { useState } from 'react';
+import { Alert, View } from 'react-native';
import { Button, Input } from 'react-native-elements';
-import { useSession } from '../../utils/AuthContext';
+
import globalStyles from '../../styles/globalStyles';
+import { useSession } from '../../utils/AuthContext';
function SignUpScreen() {
const { session, signUp, signInWithEmail } = useSession();
diff --git a/src/app/index.tsx b/src/app/index.tsx
index d834a1a6..283f48d0 100644
--- a/src/app/index.tsx
+++ b/src/app/index.tsx
@@ -1,4 +1,5 @@
import { Redirect } from 'expo-router';
+
import { useSession } from '../utils/AuthContext';
function StartPage() {
diff --git a/src/app/settings.tsx b/src/app/settings.tsx
index 9528acc6..bc6c5754 100644
--- a/src/app/settings.tsx
+++ b/src/app/settings.tsx
@@ -1,14 +1,26 @@
-import { Redirect, router } from 'expo-router';
+import { router } from 'expo-router';
+import { useEffect } from 'react';
import { Text, View } from 'react-native';
import { Button } from 'react-native-elements';
import { SafeAreaView } from 'react-native-safe-area-context';
-import { useSession } from '../utils/AuthContext';
+
import globalStyles from '../styles/globalStyles';
+import { useSession } from '../utils/AuthContext';
function SettingsScreen() {
const { session, signOut } = useSession();
- if (!session) return ;
+ const resetAndPushToRouter = (path: string) => {
+ while (router.canGoBack()) {
+ router.back();
+ }
+ router.replace(path);
+ };
+
+ useEffect(() => {
+ if (!session) resetAndPushToRouter('/auth/login');
+ }, [session]);
+
return (
Settings
diff --git a/src/utils/AuthContext.tsx b/src/utils/AuthContext.tsx
index c3081d0a..c4f68672 100644
--- a/src/utils/AuthContext.tsx
+++ b/src/utils/AuthContext.tsx
@@ -44,7 +44,7 @@ export function AuthContextProvider({
setSession(newSession);
});
- supabase.auth.onAuthStateChange((event, newSession) => {
+ supabase.auth.onAuthStateChange((_event, newSession) => {
setSession(newSession);
});
}, []);