diff --git a/src/screens/SplashScreen.tsx b/src/screens/SplashScreen.tsx index 38b6529..e424cac 100644 --- a/src/screens/SplashScreen.tsx +++ b/src/screens/SplashScreen.tsx @@ -8,6 +8,7 @@ import { BASE_URL } from "../utils/ApiUrls"; import { useDispatch, useSelector } from "react-redux"; import { setUserData } from "../redux/userSlice"; import colors from "../components/colors"; +import { ApiResponse } from "./home/UserProfileStatus"; const SplashScreen = () => { const dispatch = useDispatch(); @@ -15,6 +16,7 @@ const SplashScreen = () => { const navigation = useNavigation>(); const fadeAnim = useRef(new Animated.Value(1)).current; + const fetchUserProfile = async () => { try { const credentials = await Keychain.getGenericPassword(); @@ -69,6 +71,38 @@ const SplashScreen = () => { } }; + + const userStatus = async () => { + try { + const credentials = await Keychain.getGenericPassword(); + if (!credentials) { + Alert.alert("Error", "You are not logged in"); + return; + } + const token = credentials.password; + + const response = await fetch(`${BASE_URL}user/profile/status`, { + method: "GET", + headers: { + Accept: "*/*", + Authorization: `Bearer ${token}`, + }, + }); + + const json: ApiResponse = await response.json(); + + console.log("👤 Profile Status Response:", json); + if (json.status === "success") { + + } else { + // setError(json.message || "Failed to fetch status"); + } + } catch (err) { + // setError("Something went wrong. Please try again."); + } + }; + + console.log("redux user", user); useEffect(() => { diff --git a/src/screens/profile/Profile.tsx b/src/screens/profile/Profile.tsx index 79a6a30..36ef8f5 100644 --- a/src/screens/profile/Profile.tsx +++ b/src/screens/profile/Profile.tsx @@ -19,7 +19,7 @@ import { launchImageLibrary } from "react-native-image-picker"; import { CustomButton, CustomInput } from "../../components/common/Custom"; import colors from "../../components/colors"; import SwitchNavigator from "./SwitchNavigator"; -import { useFocusEffect } from "@react-navigation/native"; +import { useFocusEffect, useNavigation } from "@react-navigation/native"; import { ApiResponse } from "../home/UserProfileStatus"; import { BASE_URL } from "../../utils/ApiUrls"; import AppView from "../../components/AppView"; @@ -46,6 +46,7 @@ type UserProfile = { }; const Profile = () => { + const navigation = useNavigation(); const [user, setUser] = useState(null); const [fetching, setFetching] = useState(true); const [editing, setEditing] = useState(false); @@ -242,6 +243,35 @@ const Profile = () => { } }; + const logout = async (navigation: any) => { + try { + const credentials = await Keychain.getGenericPassword(); + + if (!credentials) { + Alert.alert("Info", "No user is currently logged in"); + return; + } + + // Clear stored credentials + await Keychain.resetGenericPassword(); + Alert.alert("Success", "You have been logged out"); + navigation.replace("Login"); + } catch (error) { + console.error("Logout error:", error); + Alert.alert("Error", "Failed to log out. Please try again."); + } +}; + + const confirmLogout = (navigation: any) => { + Alert.alert( + "Logout", + "Are you sure you want to log out?", + [ + { text: "Cancel", style: "cancel" }, + { text: "Yes, Logout", style: "destructive", onPress: () => logout(navigation) }, + ] + ); +}; useFocusEffect( @@ -281,7 +311,7 @@ const Profile = () => { {/* Header */} User Profile - + confirmLogout(navigation)} style={styles.refreshButton}>