我是否在使用Firebase JS SDK还是React-Native-Firebase?
P粉083785014
P粉083785014 2023-09-02 18:27:28
0
1
435
<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 ( &lt;View style={styles.container}&gt;&lt;Text&gt;打开App.js开始开发您的应用程序!&lt;/Text&gt;&lt;StatusBar style="auto" /&gt;&lt;Button title="Google登录" onPress={() =&gt; onGoogleButtonPress().then(() =&gt; console.log('使用Google登录!'))}/&gt;&lt;/View&gt;);}) ) const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},});</pre> <p>我不确定从哪里开始</p>
P粉083785014
P粉083785014

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!