不知道我使用的是Firebase JS SDK还是React-Native-Firebase



我已经使用Firebase的JS SDK创建了一个大型web应用程序,现在我正在过渡到使用React-Native, Expo的移动应用程序。由于我使用的是Expo,所以我创建了一个开发客户端,这样我就不用Expo Go了,因为RNFirebase使用本地代码。我的目标:实现与React-Native-Firebase认证链接的基本Google登录

我已经安装了"react-native-firebase/app" react-native-firebase/auth">

然而,当我试图使用谷歌的登录(https://rnfirebase.io/auth/social-auth)进行身份验证时,我一直得到一个错误,说'[DEFAULT]' firebase应用程序未初始化。

所以,我遵循了另一个指南,其中(我不知道它是否正确),告诉我创建一个firebase.js文件,就像我的web应用程序那样:

import firebase from '@react-native-firebase/app';
import auth from '@react-native-firebase/auth';
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
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 }

现在,认证工作,但我不知道如果我还在使用RNFirebase或如果我使用Firebase的JS SDK。有人能回答吗?这是我的认证码:

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() {
// Check if your device supports Google Play
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
// Get the users ID token
console.log(GoogleSignin);
const { idToken } = await GoogleSignin.signIn();
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
// Sign-in the user with the credential
return auth().signInWithCredential(googleCredential);// console.log("YOOOOOOO5")// console.log(res)}

return (
<View style={styles.container}><Text>Open up App.js to start working on your app!</Text><StatusBar style="auto" /><Buttontitle="Google Sign-In"onPress={() => onGoogleButtonPress().then(() => console.log('Signed in with Google!'))}/></View>);})
)
const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},});

我不知道从哪里开始

给定这行代码中的auth().signInWithCredential,您仍然在使用react-native-firebase库:

return auth().signInWithCredential(googleCredential);

在Firebase JavaScript SDK中,这将是firebase.auth().signInWithCredentialsignInWithCredential(auth, ...

最新更新