Last active
February 11, 2025 02:22
-
-
Save duzitug/7f132187edf022579358f5c52098a560 to your computer and use it in GitHub Desktop.
Autenticacao gerado por IA expo-auth-session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Google from "expo-auth-session/providers/google"; | |
import { signInWithCredential, GoogleAuthProvider } from "firebase/auth"; | |
import { auth } from "../firebase"; | |
import { useAuth } from "../contextoAutenticacaoFirebase"; | |
import { useNavigation } from "@react-navigation/native"; | |
import * as AuthSession from "expo-auth-session"; | |
export function AutenticacaoGoogle() { | |
const [error, setError] = useState(null); | |
const { navigate } = useNavigation(); | |
const { usuario, setarUsuario } = useAuth(); | |
const redirectUri = AuthSession.makeRedirectUri({ | |
useProxy: true, | |
projectNameForProxy: "@merciof/libras-app", | |
}); | |
console.log("Redirect URI:", redirectUri); | |
const [request, response, promptAsync] = Google.useIdTokenAuthRequest({ | |
clientId: "", | |
redirectUri: redirectUri, | |
useProxy: true, | |
}); | |
useEffect(() => { | |
if (response?.type === "success") { | |
const { id_token } = response.params; | |
const credential = GoogleAuthProvider.credential(id_token); | |
signInWithCredential(auth, credential) | |
.then((userCredential) => { | |
console.log("Usuário logado:", userCredential.user.uid); | |
setarUsuario(userCredential.user); | |
navigate("EnviarDados"); | |
}) | |
.catch((error) => { | |
setError(error.message); | |
console.error(error); | |
}); | |
} | |
}, [response]); | |
return ( | |
<View style={styles.container}> | |
{usuario ? ( | |
<View> | |
<Text>Bem-vindo, {usuario.displayName}!</Text> | |
<Text>Email: {usuario.email}</Text> | |
<Button | |
style={styles.button} | |
title="Continuar" | |
onPress={() => navigate("EnviarDados")} | |
/> | |
</View> | |
) : ( | |
<View> | |
<Text>{error || ""}</Text> | |
<Image | |
source={{ uri: "https://www.stickersdevs.com.br/wp-content/uploads/2020/09/google-logo-sticker-adesivo-800x800.jpg" }} | |
style={styles.image} | |
/> | |
<Button | |
title="Continuar com conta Google" | |
onPress={() => promptAsync()} | |
disabled={!request} | |
/> | |
</View> | |
)} | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment