Firebase身份验证-登录问题

时间:2020-09-03 11:32:50

标签: reactjs firebase google-cloud-firestore react-redux firebase-authentication

我得到了登录表格-SignIn.js

<form onSubmit={this.onSubmit}>
    <div className="form-group">
        <label htmlFor="email">Email</label>
        <input type="text" className="form-control" name="email" value={this.state.email} onChange={this.onChange} />
    </div>
    <div className="form-group">
        <label htmlFor="password">Password</label>
        <input type="password" className="form-control" name="password" value={this.state.password} onChange={this.onChange} />
    </div>
    <input type="submit" value="Login" className="btn btn-primary btn-block" />
</form>
...  
export default firebaseConnect()(SignIn);

onSubmit ,我要在其中登录 Firebase / Firestore

 onSubmit = e => {
    e.preventDefault();

    const { firebase } = this.props;
    const { email, password } = this.state;

    firebase
      .login({email, password})
      .catch(err => alert('Invalid Login Credentials'));
  };

当我尝试登录时出现此错误:

TypeError: firebase.auth is not a function

我也尝试过这个:

firebase.auth().signInWithEmailAndPassword(email, password);

但是我遇到了同样的问题。

我的商店

const rootReducer = combineReducers({
  firebase: firebaseReducer,
  firestore: firestoreReducer});
const initialState = {};    
const store = createStore(
  rootReducer,
  initialState,
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());

const rrfProps = {
 firebase,
 config: {},
 dispatch: store.dispatch,
 createFirestoreInstance};

ReactDOM.render(
  <Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfProps}>

      <App />

    </ReactReduxFirebaseProvider>
  </Provider>,
  document.getElementById("root")
);

firebaseConfig .js

const fc = {
//data from Firebase (apiKey, authDomain...)
}    
firebase.initializeApp(fc);
firebase.firestore();
export default firebase;

1 个答案:

答案 0 :(得分:1)

基于firebase.auth is not a function,我在firebaseConfig.js内执行了以下操作

import firebase from "firebase";
import "firebase/firestore";

同样可以正常工作:

import firebase from "firebase/app";
import "firebase/firestore";
import "firebase/auth";