OAuth implemented

This commit is contained in:
Sanidhya Kumar Verma
2024-09-04 11:38:47 +00:00
committed by GitHub
parent 8cb07ae079
commit 1f0ecd696d
2 changed files with 88 additions and 3 deletions
+24 -3
View File
@@ -1,15 +1,36 @@
import { Image, Text, View } from "react-native";
import { useOAuth } from "@clerk/clerk-expo";
import { useCallback } from "react";
import { Alert, Image, Text, View } from "react-native";
import { icons } from "@/constants";
import { CustomButton } from "./custom-button";
import { googleOAuth } from "@/lib/auth";
import { router } from "expo-router";
type OAuthProps = {
title: string;
};
export const OAuth = ({ title }: OAuthProps) => {
const handleGoogleSignIn = () => {};
const { startOAuthFlow } = useOAuth({ strategy: "oauth_google" });
const handleGoogleOAuth = useCallback(async () => {
try {
const result = await googleOAuth(startOAuthFlow);
if (result?.code === "session_exists") {
router.replace("/(root)/(tabs)/home");
}
Alert.alert(
result?.success ? "Success" : "Error",
result?.message || "You are Logged In!",
);
} catch (err) {
console.error("OAuth error", err);
}
}, [startOAuthFlow]);
return (
<View>
@@ -34,7 +55,7 @@ export const OAuth = ({ title }: OAuthProps) => {
)}
bgVariant="outline"
textVariant="primary"
onPress={handleGoogleSignIn}
onPress={handleGoogleOAuth}
/>
</View>
);