search

Home  >  Q&A  >  body text

Am I using Firebase JS SDK or React-Native-Firebase?

<p>I created a large web app using Firebase's JS SDK and now I'm transitioning to a mobile app using React-Native and Expo. Since I use Expo, I created a development client so as not to use Expo Go since RNFirebase uses native code. <strong>My goal: Implement basic Google login tied to React-Native-Firebase Authentication</strong></p> <p>I have installed "react-native-firebase/app" and "react-native-firebase/auth" using npm</p> <p>However, when I try to use Google's login authentication (https://rnfirebase.io/auth/social-auth), I keep getting an error saying '[DEFAULT]' firebase app is not initialized. </p> <p>So, I followed another guide (I don't know if it's correct) which told me to create a firebase.js file similar to my web application with the following content: </p> <pre class="brush:php;toolbar:false;">import firebase from '@react-native-firebase/app'; import auth from '@react-native-firebase/auth'; // For Firebase JS SDK v7.20.0 and above, 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 }</pre> <p>Now, the authentication works, but I don't know if I'm still using RNFirebase or using Firebase's JS SDK.Can anyone answer this? This is my authentication code: </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() { // Check if the device supports Google Play await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true }); // Get the user's ID token console.log(GoogleSignin); const { idToken } = await GoogleSignin.signIn(); const googleCredential = auth.GoogleAuthProvider.credential(idToken); // Log in user using credentials return auth().signInWithCredential(googleCredential);// console.log("YOOOOOOOO5")// console.log(res)} return ( <View style={styles.container}><Text>Open App.js to start developing your application! </Text><StatusBar style="auto" /><Button title="Google Login" onPress={() => onGoogleButtonPress().then(() => console.log('Use Sign in with Google!'))}/></View>);}) ) const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},});</pre> <p>I’m not sure where to start</p>
P粉083785014P粉083785014455 days ago620

reply all(1)I'll reply

  • P粉682987577

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

    In this line of code, auth().signInWithCredential is used, and you are still using the react-native-firebase library:

    return auth().signInWithCredential(googleCredential);

    In the Firebase JavaScript SDK, this might be firebase.auth().signInWithCredential or signInWithCredential(auth, ....

    reply
    0
  • Cancelreply