Skip to content

Instantly share code, notes, and snippets.

@williamjayjay
Created July 19, 2025 17:18
Show Gist options
  • Save williamjayjay/13d266f0797d194077fb6dfd248e955b to your computer and use it in GitHub Desktop.
Save williamjayjay/13d266f0797d194077fb6dfd248e955b to your computer and use it in GitHub Desktop.
App to get and show accessToken send by Cloud Function
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