>  Q&A  >  본문

Firebase JS SDK 또는 React-Native-Firebase를 사용하고 있나요?

<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>
P粉083785014P粉083785014413일 전575

모든 응답(1)나는 대답할 것이다

  • P粉682987577

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

    이 코드 줄에서는 auth().signInWithCredential ,你仍然在使用 react-native-firebase 라이브러리가 사용됩니다:

    으아악

    Firebase JavaScript SDK에서는 firebase.auth().signInWithCredential 或者 signInWithCredential(auth, ...일 수 있습니다.

    회신하다
    0
  • 취소회신하다