I'm testing react-native (android) with firebase, and I did a small app to auth on firebase.
The problem is, when I hit R+R 3 or 4 times, firebase stops authenticate user.
In ./src/actions/login.js have a console.log that I put to try to debug. When promisses (.then()) occur, I have another console.log(user), but when I reload the app 3 or 4 times the console.log(user) stop to appear. But the others two console.log (starting auth) and console.log(finish auth) works every time.
If I close Metro Bundler and open again, the authentication process will working on the first time, second time, but if I reload app 3 or 4 times (sometimes needs a lot of R+R), authentication process will not occurs and I can't get error on .catch().
Someone are facing this problem or could help me? Thanks.
Here is my code:
./src/config/app_config_firebase.js
import firebase from 'firebase';
import {
FIREBASE_API_KEY,
FIREBASE_AUTH_DOMAIN,
FIREBASE_DATABASE_URL,
FIREBASE_PROJECT_ID,
FIREBASE_STORAGE_BUCKET,
FIREBASE_MESSAGING_SENDER_ID
} from './constants';
const config = {
apiKey: FIREBASE_API_KEY,
authDomain: FIREBASE_AUTH_DOMAIN,
databaseURL: FIREBASE_DATABASE_URL,
projectId: FIREBASE_PROJECT_ID,
storageBucket: FIREBASE_STORAGE_BUCKET,
messagingSenderId: FIREBASE_MESSAGING_SENDER_ID
};
firebase.initializeApp(config);
export const database = firebase.database();
export const auth = firebase.auth();
./src/actions/login.js
import { auth } from '../config/app_config_firebase';
export const loginUser = () => {
console.log('starting auth');
auth.signInWithEmailAndPassword('[email protected]', '123456')
.then((user) => console.log(user))
.catch(erro => console.log(erro));
console.log('finish auth');
}
./App.js
import React, { Component } from 'react';
import {
View,
Button
} from 'react-native';
import { loginUser } from './src/actions/login';
export default class App extends Component {
_autenticarUsuario() {
loginUser();
}
render() {
return (
<View>
<Button
title='Login'
onPress={() => this._autenticarUsuario()}
/>
</View>
);
}
}