Created
July 19, 2025 17:18
-
-
Save williamjayjay/13d266f0797d194077fb6dfd248e955b to your computer and use it in GitHub Desktop.
App to get and show accessToken send by Cloud Function
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 { StatusBar } from 'expo-status-bar'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
import { useEffect, useState } from 'react'; | |
import functions from '@react-native-firebase/functions'; | |
export default function App() { | |
const [token, setToken] = useState<string | null>(null); | |
const [error, setError] = useState<string | null>(null); | |
useEffect(() => { | |
const fetchToken = async () => { | |
try { | |
const callableMetal = functions().httpsCallable('getMetalcodeAccessToken'); | |
const resultMetal = await callableMetal(); | |
const fetchedTokenMetal = resultMetal.data.token; | |
console.log('Token obtido:', fetchedTokenMetal); // Log do token | |
setToken(fetchedTokenMetal); // Armazena o token no estado | |
} catch (err) { | |
console.error('Erro ao obter o token:', err); | |
setError('Falha ao obter o token'); | |
} | |
}; | |
fetchToken(); | |
}, []); | |
return ( | |
<View style={styles.container}> | |
<Text>Open up App.tsx to start working on your app!</Text> | |
{token ? ( | |
<Text>Token: {token}</Text> | |
) : error ? ( | |
<Text style={styles.error}>{error}</Text> | |
) : ( | |
<Text>Carregando token...</Text> | |
)} | |
<StatusBar style="auto" /> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
backgroundColor: '#fff', | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
error: { | |
color: 'red', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment