fix oauth flow

This commit is contained in:
Sanidhya Kumar Verma
2024-09-04 11:53:27 +00:00
committed by GitHub
parent 1f0ecd696d
commit 04694246c0
4 changed files with 51 additions and 14 deletions
+43 -2
View File
@@ -1,10 +1,51 @@
import { Text } from "react-native"; import { useUser } from "@clerk/clerk-expo";
import { ActivityIndicator, FlatList, Image, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context"; import { SafeAreaView } from "react-native-safe-area-context";
import { RideCard } from "@/components/ride-card";
import { images } from "@/constants";
import { useFetch } from "@/lib/fetch";
import type { Ride } from "@/types/type";
const Rides = () => { const Rides = () => {
const { user } = useUser();
const { data: recentRides, loading } = useFetch<Ride[]>(
`/(api)/ride/${user?.id}`,
);
return ( return (
<SafeAreaView> <SafeAreaView>
<Text>Rides</Text> <FlatList
data={recentRides}
renderItem={({ item }) => <RideCard ride={item} />}
className="px-5"
keyboardShouldPersistTaps="handled"
contentContainerStyle={{
paddingBottom: 100,
}}
ListEmptyComponent={() => (
<View className="flex flex-col items-center justify-center">
{!loading ? (
<>
<Image
source={images.noResult}
alt="No recent rides found"
className="w-40 h-40"
resizeMode="contain"
/>
<Text className="text-sm">No recent rides found.</Text>
</>
) : (
<ActivityIndicator size="small" color="#000" />
)}
</View>
)}
ListHeaderComponent={() => (
<>
<Text className="text-2xl font-JakartaBold my-5">All rides</Text>
</>
)}
/>
</SafeAreaView> </SafeAreaView>
); );
}; };
+3
View File
@@ -4,6 +4,7 @@ import { Stack } from "expo-router";
import * as SplashScreen from "expo-splash-screen"; import * as SplashScreen from "expo-splash-screen";
import { StatusBar } from "expo-status-bar"; import { StatusBar } from "expo-status-bar";
import { useEffect } from "react"; import { useEffect } from "react";
import { LogBox } from "react-native";
import "react-native-reanimated"; import "react-native-reanimated";
import { tokenCache } from "@/lib/auth"; import { tokenCache } from "@/lib/auth";
@@ -11,6 +12,8 @@ import { tokenCache } from "@/lib/auth";
// Prevent the splash screen from auto-hiding before asset loading is complete. // Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync(); SplashScreen.preventAutoHideAsync();
LogBox.ignoreAllLogs();
const RootLayout = () => { const RootLayout = () => {
const [loaded] = useFonts({ const [loaded] = useFonts({
"Jakarta-Bold": require("../assets/fonts/PlusJakartaSans-Bold.ttf"), "Jakarta-Bold": require("../assets/fonts/PlusJakartaSans-Bold.ttf"),
+2 -7
View File
@@ -1,6 +1,6 @@
import { useOAuth } from "@clerk/clerk-expo"; import { useOAuth } from "@clerk/clerk-expo";
import { useCallback } from "react"; import { useCallback } from "react";
import { Alert, Image, Text, View } from "react-native"; import { Image, Text, View } from "react-native";
import { icons } from "@/constants"; import { icons } from "@/constants";
@@ -19,14 +19,9 @@ export const OAuth = ({ title }: OAuthProps) => {
try { try {
const result = await googleOAuth(startOAuthFlow); const result = await googleOAuth(startOAuthFlow);
if (result?.code === "session_exists") { if (result?.code === "session_exists" || result?.code === "success") {
router.replace("/(root)/(tabs)/home"); router.replace("/(root)/(tabs)/home");
} }
Alert.alert(
result?.success ? "Success" : "Error",
result?.message || "You are Logged In!",
);
} catch (err) { } catch (err) {
console.error("OAuth error", err); console.error("OAuth error", err);
} }
+3 -5
View File
@@ -17,15 +17,13 @@ export const tokenCache = {
async getToken(key: string) { async getToken(key: string) {
try { try {
const item = await SecureStore.getItemAsync(key); const item = await SecureStore.getItemAsync(key);
if (item) {
console.log(`${key} was used 🔐 \n`);
} else {
console.log("No values stored under key: " + key);
}
return item; return item;
} catch (error) { } catch (error) {
console.error("GET_TOKEN_CACHE: ", error); console.error("GET_TOKEN_CACHE: ", error);
await SecureStore.deleteItemAsync(key); await SecureStore.deleteItemAsync(key);
return null; return null;
} }
}, },