From 139fbd895a460b4539137372db431bab404bd7e0 Mon Sep 17 00:00:00 2001 From: patela22 <39590072+patela22@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:43:01 -0500 Subject: [PATCH] Feature/login (#18) * feat(Firebase.config): Created the authentication connection Created the login, the signup, and authstate functions * Added dependency for firebase/auth * Added stub for login landing page. Updated mod and sum * Updated firebase dependency * Login tests * feat(Client): Created a simple login page Auth works + login page works + alerts * fix(Auth): Makes react native remember login * fix(Login): Ready for PR * fix(PR-Changes): Added the fixes for PR * fix: deleting package.json * refactor: Fixed gitignore * fix(login-navigation): added simple navigation to login page for added functionality --------- Co-authored-by: bedrockdude10 Co-authored-by: andrewcaplan1 Co-authored-by: Andrew Caplan <60331997+andrewcaplan1@users.noreply.github.com> --- client/App.tsx | 8 ++- client/firebase.config.js | 21 +++++++ client/package.json | 7 ++- client/screens/Landing.tsx | 0 client/screens/Login.tsx | 70 ++++++++++++++++++++++++ client/services/auth/authState.ts | 13 +++++ client/services/auth/login.ts | 37 +++++++++++++ client/services/auth/signup.ts | 20 +++++++ client/services/auth/tests/login.test.ts | 30 ++++++++++ 9 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 client/firebase.config.js create mode 100644 client/screens/Landing.tsx create mode 100644 client/screens/Login.tsx create mode 100644 client/services/auth/authState.ts create mode 100644 client/services/auth/login.ts create mode 100644 client/services/auth/signup.ts create mode 100644 client/services/auth/tests/login.test.ts diff --git a/client/App.tsx b/client/App.tsx index 8176493..947b824 100644 --- a/client/App.tsx +++ b/client/App.tsx @@ -3,11 +3,12 @@ import { Text } from 'react-native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { NavigationContainer, NavigationProp } from '@react-navigation/native'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; +import LoginPage from './screens/Login'; import MedList from './screens/Medication'; import Home from './assets/home.svg'; import DocPickerButton from './components/DocPickerButton'; -export type ScreenNames = ['BottomNav', 'Landing', 'TEMP-FileUpload']; +export type ScreenNames = ['BottomNav', 'Landing', 'TEMP-FileUpload', 'Login']; export type RootStackParamList = Record; export type StackNavigation = NavigationProp; @@ -19,6 +20,11 @@ export default function App() { return ( + { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + const navigation = useNavigation(); + const route = useRoute(); + + const handleLogin = async () => { + if (!email || !password) { + Alert.alert('Error', 'Email and password are required'); + return; + } + const result = await logIn(email, password); + if (typeof result === 'string') { + Alert.alert('Login Failed', result.substring(5).replaceAll('-', ' ')); + } else { + Alert.alert('Login Success', 'Welcome back!'); + // console.log('result: ', result); + navigation.navigate('BottomNav'); + } + }; + + const handleSignUp = async () => { + if (!email || !password) { + Alert.alert('Error', 'Email and password are required'); + return; + } + const result = await signUp(email, password); + if (typeof result === 'string') { + Alert.alert('Signup Failed', result.substring(5).replaceAll('-', ' ')); + } else { + Alert.alert('Signup Success', 'Welcome to the app!'); + // console.log('result: ', result); + navigation.navigate('BottomNav'); + } + }; + + return ( + + + +