Firebase JS SDK ?? React-Native-Firebase? ???? ????
P粉083785014
2023-09-02 18:27:28
<p>Firebase? JS SDK? ???? ??? ? ?? ???? ??? React-Native ? Expo? ???? ??? ??? ???? ????. ?? Expo? ???? ??? RNFirebase? ???? ??? ???? ??? Expo Go? ???? ??? ?? ?????? ??????.
<strong>? ??: React-Native-Firebase ??? ??? ?? Google ??? ??
<p>npm</p>? ???? "react-native-firebase/app" ? "react-native-firebase/auth"? ??????.
<p>??? Google? ??? ??(https://rnfirebase.io/auth/social-auth)? ????? ?? '[DEFAULT]' Firebase ?? ????? ???? ??? ???? ?????. </p>
<p>??? ?? ?? ???? ? ? ??????? ??? firebase.js ??? ????? ?? ???(???? ??????)? ?????. </p>
<pre class="brush:php;toolbar:false;">'@react-native-firebase/app'?? Firebase ????;
'@react-native-firebase/auth'?? ??? ?????.
// Firebase JS SDK v7.20.0 ??? ?? ?? ID? ???????.
const firebaseConfig = {apiKey: "AIzaSyCoNUZI0-Mir9hGtXUJJmIrML88JxSOJAk",authDomain: "campus-market-25068.firebaseapp.com",databaseURL: "https://campus-market-25068-default-rtdb.firebaseio.com",projectId: "campus-market-25068",storageBucket: "campus-market-25068.appspot.com",messagingSenderId: "315015080294",appId: "1:315015080294:web:53dbed097963d67b92c0a7",measurementId: "G-5TVXC2MQ7S "} ;if (!firebase.apps.length) {firebase.initializeApp(firebaseConfig);}export { firebase, auth }</pre>
<p>?? ??? ????? ?? RNFirebase? ???? ??? ??? Firebase? JS SDK? ???? ??? ??????.???? ??? ??? ? ???? ? ?? ??? ??? ????. </p>
<pre class="brush:php;toolbar:false;">'expo-dev-client' ????
'??'?? ???? { useState, useEffect };
'expo-status-bar'?? { StatusBar }? ?????.
import { StyleSheet, Text, View, Button } from 'react-native';
// './src/firebase' ????;/
/import * '@react-native-firebase/app'?? Firebase?;
import { auth } from './firebase';
'@react-native-google-signin/google-signin'?? { GoogleSignin }? ?????.
?? ?? ???? App() {
GoogleSignin.configure({
webClientId: '315015080294-gejpuoaedqhbcve32dat55gg4cn5va3j.apps.googleusercontent.com',
});
GoogleButtonPress()? ??? ?? {
// ??? Google Play? ????? ?????.
GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true })? ?????.
// ???? ID ??? ?????.
console.log(GoogleSignin);
const { idToken } = GoogleSignin.signIn()? ?????.
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
// ?? ??? ???? ??? ???
return auth().signInWithCredential(googleCredential);// console.log("YOOOOOOOO5")// console.log(res)}
?? (
<View style={styles.container}><Text>App.js? ?? ?????? ??? ?????! </Text><StatusBar style="auto" /><Button title="Google ???" onPress={() => onGoogleButtonPress().then(() => console.log('?? ?? ???! '))}/></??>);})
)
const styles = StyleSheet.create({container: {flex: 1, backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},});</pre>
<p>???? ???? ?? ??????</p>
? ?? ???? auth().signInWithCredential
,你仍然在使用 react-native-firebase
?????? ?????:
???
Firebase JavaScript SDK??? firebase.auth().signInWithCredential
或者 signInWithCredential(auth, ...
? ? ????.
?? +0
P粉083785014