首页  >  问答  >  正文

我是否在使用Firebase JS SDK还是React-Native-Firebase?

<p>我使用Firebase的JS SDK创建了一个大型的Web应用程序,现在我正在使用React-Native和Expo过渡到移动应用程序。由于我使用Expo,我创建了一个开发客户端,以便不使用Expo Go,因为RNFirebase使用本地代码。 <strong>我的目标:实现与React-Native-Firebase身份验证相关联的基本Google登录</strong></p> <p>我已经使用npm安装了"react-native-firebase/app"和"react-native-firebase/auth"</p> <p>然而,当我尝试使用Google的登录验证(https://rnfirebase.io/auth/social-auth)时,我一直收到一个错误,说'[DEFAULT]' firebase app未初始化。</p> <p>所以,我按照另一个指南(我不知道是否正确),告诉我创建一个类似于我的Web应用程序的firebase.js文件,其中包含以下内容:</p> <pre class="brush:php;toolbar:false;">import firebase from '@react-native-firebase/app'; import auth from '@react-native-firebase/auth'; // 对于Firebase JS SDK v7.20.0及更高版本,measurementId是可选的 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;">import 'expo-dev-client' import { useState, useEffect } from 'react'; import { StatusBar } from 'expo-status-bar'; import { StyleSheet, Text, View, Button } from 'react-native'; // import './src/firebase';/ / import * as firebase from '@react-native-firebase/app'; import { auth } from './firebase'; import { GoogleSignin } from '@react-native-google-signin/google-signin'; export default function App() { GoogleSignin.configure({ webClientId: '315015080294-gejpuoaedqhbcve32dat55gg4cn5va3j.apps.googleusercontent.com', }); async function onGoogleButtonPress() { // 检查设备是否支持Google Play await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true }); // 获取用户的ID令牌 console.log(GoogleSignin); const { idToken } = await GoogleSignin.signIn(); const googleCredential = auth.GoogleAuthProvider.credential(idToken); // 使用凭据登录用户 return auth().signInWithCredential(googleCredential);// console.log("YOOOOOOO5")// console.log(res)} return ( <View style={styles.container}><Text>打开App.js开始开发您的应用程序!</Text><StatusBar style="auto" /><Button title="Google登录" onPress={() => onGoogleButtonPress().then(() => console.log('使用Google登录!'))}/></View>);}) ) const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},});</pre> <p>我不确定从哪里开始</p>
P粉083785014P粉083785014413 天前577

全部回复(1)我来回复

  • P粉682987577

    P粉6829875772023-09-03 13:22:20

    在这行代码中,使用了 auth().signInWithCredential ,你仍然在使用 react-native-firebase 库:

    return auth().signInWithCredential(googleCredential);

    在 Firebase JavaScript SDK 中,这可能是 firebase.auth().signInWithCredential 或者 signInWithCredential(auth, ...

    回复
    0
  • 取消回复