调度操作不适用于createUserWithEmailAndPassword firebase



我同时使用Redux和Firebase(即Auth、Firestore(,此外还使用Expo,因为我没有使用React Native本身的经验。正在尝试设置注册和登录操作,但不起作用。我到处寻找例子和问题,阅读文档,发现其他人也在用和我一样的方式做,但我就是做不到。没有收到任何错误信息或任何东西都是一件非常令人沮丧的事情。

我还没有开始使用Redux部分,因为我正在尝试使用Firebase进行身份验证。

奇怪的是,我两年前在另一个项目中使用了这些代码,效果很好。

感谢任何输入,谢谢

App.js:

import { combineReducers, createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import ReduxThunk from 'redux-thunk';
import authReducer from './src/redux/reducers/auth';
const rootReducer = combineReducers({
authState: authReducer
});
const store = createStore(rootReducer, applyMiddleware(ReduxThunk));
return (
<Provider store={store}>
<The rest of the App />
</Provider>
);

auth.js的操作:(在代码中进行注释,以显示其中断的位置(

import firebase from '../../api/';
const db = firebase.firestore();
export const signUp = (email, password, name) => {
let signUpResponse;
// DOES REACH HERE
// This does not work
return async dispatch => {
// DOES NOT ENTER HERE AT ALL.
await firebase
.auth()
.createUserWithEmailAndPassword(email, password) // Could have broken here
.then(res => {
console.log(res); // Doesn't even print this
signUpResponse = res.user;
firebase
.auth()
.currentUser.updateProfile({ displayName: name })
.then(() => {
dispatch({ type: GET_USER, user: signUpResponse.displayName });
})
.catch(err => console.log('err.message', err.message));
})
.catch(err => {
let message = 'An error has occured!';
let errorPresent =
err.code === 'auth/email-already-in-use' ||
err.code === 'auth/invalid-email' ||
err.code === 'auth/weak-password';
if (errorPresent) {
message = 'Invalid Credentials!';
}
throw new Error(message);
});
};
// This works from Firebase Auth docs
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(userCredential => {
// Signed in
var user = userCredential.user;
// ...
})
.catch(error => {
var errorCode = error.code;
var errorMessage = error.message;
// ..
});
};

auth.js:的还原器

import { GET_USER } from '../constants/index';
const initialState = {
name: ''
};
export default (state = initialState, action) => {
switch (action.type) {
case GET_USER:
return {
...state,
name: action.user
};
default:
return state;
}
};

Firebase init:

import ENV from '../../env';
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/storage';
require('firebase/firestore');
if (firebase.apps.length === 0) {
console.log('init firebase success'); // Successful here at every run
firebase.initializeApp(ENV().firebaseConfig);
}
export default firebase;

相反,学习并使用了Redux Toolkit。现在就结束。

相关内容

  • 没有找到相关文章