From d143d38a55b812bc67c7e85ecdba0922f72da633 Mon Sep 17 00:00:00 2001 From: mansi-dev Date: Tue, 17 Feb 2026 22:52:20 +0530 Subject: [PATCH] Managed the authentication flow and worked on the overall UI design. --- src/Route.tsx | 94 ++++++++++++++++++++++++++++++++++++++++++++++ src/auth/Login.tsx | 10 +++++ 2 files changed, 104 insertions(+) create mode 100644 src/Route.tsx create mode 100644 src/auth/Login.tsx diff --git a/src/Route.tsx b/src/Route.tsx new file mode 100644 index 0000000..fb789be --- /dev/null +++ b/src/Route.tsx @@ -0,0 +1,94 @@ +import { createContext, useContext, useEffect, useState } from 'react'; +import { View, ActivityIndicator } from 'react-native'; + +/* ---------- AUTH SCREENS ---------- */ +import { Login } from './auth/Login'; +/* ---------- APP SCREENS ---------- */ +import Home from './Screen/Home'; +const AuthStack = createNativeStackNavigator(); +const MainStack = createNativeStackNavigator(); +type AuthContextType = { + isLoggedIn: boolean; + setIsLoggedIn: (value: boolean) => void; +}; + + +const AuthContext = createContext(undefined); + +export const useAuth = () => { + const context = useContext(AuthContext); + if (!context) { + throw new Error('useAuth must be used within AuthProvider'); + } + return context; +}; + +function AuthStackNavigator() { + return ( + + + + + + ); +} + +function MainStackNavigator() { + return ( + + + + ); +} + +function RootNavigator() { + const { isLoggedIn } = useAuth(); + return isLoggedIn ? : ; +} + +const Route: React.FC = () => { + const [isLoggedIn, setIsLoggedIn] = useState(false); + const [loading, setLoading] = useState(true); + useEffect(() => { + bootstrap(); + }, []); + + const bootstrap = async () => { + try { + const keys = await AsyncStorage.getAllKeys(); + const stores = await AsyncStorage.multiGet(keys); + + stores.forEach(([key, value]) => { + if (value !== null) { + User[key] = value; + } + }); + + if (User.id) { + setIsLoggedIn(true); + } + } catch (e) { + console.log('Bootstrap error', e); + } finally { + setLoading(false); + } + }; + + + if (loading) { + return ( + + + + ); + } + return ( + + + + + + ); +}; + +export default Route; diff --git a/src/auth/Login.tsx b/src/auth/Login.tsx new file mode 100644 index 0000000..35ae823 --- /dev/null +++ b/src/auth/Login.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import { View } from "react-native"; + +export const Login: React.FC = () => { + return ( + + {/* Implement your login form here */} + + ); +}; \ No newline at end of file