我是否在使用Firebase JS SDK還是React-Native-Firebase?
P粉083785014
P粉083785014 2023-09-02 18:27:28
0
1
408
<p>我使用Firebase的JS SDK創建了一個大型的網路應用程序,現在我正在使用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>所以,我按照另一個指南(我不知道是否正確),告訴我創建一個類似於我的網路應用程式的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.firebaseapp.com",databaseURL: "https://campus-market-25068.firebaseapp.com",databaseURL: "https://campus-market-25068-defaultio. "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粉083785014
P粉083785014

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!