颤振、Redux和Firebase验证无效参数错误
我正在开发颤振应用程序,并将firebase auth添加到项目中。Google SignIn运行良好,但我不明白make如何使用电子邮件和密码登录 我将在那里学习这个例子 我已经添加了操作、还原程序和中间件,它们遵循谷歌登录的指导原则,但在电子邮件和密码的情况下会发生一些奇怪的情况 以下是日志:颤振、Redux和Firebase验证无效参数错误,firebase,redux,firebase-authentication,flutter,Firebase,Redux,Firebase Authentication,Flutter,我正在开发颤振应用程序,并将firebase auth添加到项目中。Google SignIn运行良好,但我不明白make如何使用电子邮件和密码登录 我将在那里学习这个例子 我已经添加了操作、还原程序和中间件,它们遵循谷歌登录的指导原则,但在电子邮件和密码的情况下会发生一些奇怪的情况 以下是日志: I/FirebaseAuth(27942): [FirebaseAuth:] Loading module via FirebaseOptions. I/FirebaseAuth(27942): [F
I/FirebaseAuth(27942): [FirebaseAuth:] Loading module via FirebaseOptions.
I/FirebaseAuth(27942): [FirebaseAuth:] Preparing to create service connection to gms implementation
D/FirebaseAuth(27942): Notifying id token listeners about user ( MZr9euoZKEbWWqNIrB5OcZIWcwf2 ).
D/FirebaseApp(27942): Notifying auth state listeners.
D/FirebaseApp(27942): Notified 0 auth state listeners.
I/flutter (27942): [INFO] LoggingMiddleware: {Action: LogInWithMailAndPasswordFail{There was an error loggin in: Invalid argument(s)}, State: AppState{isLoading: false, currentUser: null}}, ts: 2018-12-27 09:03:18.185480}
I/flutter (27942): [INFO] LoggingMiddleware: {Action: Instance of 'LogInWithMailAndPassword', State: AppState{isLoading: false, currentUser: null}}, ts: 2018-12-27 09:03:18.199120}
正如您在现实中看到的那样,登录工作正常,但在调用操作LogInWithMailAndPasswordFail之后立即进行
此处是中间件代码的一部分:
Middleware<AppState> _createLogInWithMailAndPasswordMiddleware() {
// These functions will always take
// your store,
// the action thats been dispatched
// and the a special function called next.
return (Store store, action, NextDispatcher next) async {
// FirebaseUser is the type of your User.
FirebaseUser user;
// Firebase 'instances' are temporary instances which give
// you access to your FirebaseUser. This includes
// some tokens we need to sign in.
final FirebaseAuth _auth = FirebaseAuth.instance;
if (action is LogInWithMailAndPassword) {
try {
user = await _auth.signInWithEmailAndPassword(
email: action.getUsername(),
password: action.getPassword());
print('Logged in ' + user.displayName);
// This can be tough to reason about -- or at least it was for me.
// We're going to dispatch a new action if we logged in,
//
// We also continue the current cycle below by calling next(action).
store.dispatch(new LogInWithMailAndPasswordSuccessful(user: user));
} catch (error) {
store.dispatch(new LogInWithMailAndPasswordFail(error));
}
}
// After you do whatever logic you need to do,
// call this Redux built-in method,
// It continues the redux cycle.
next(action);
};
}
中间件\u createLogInWithMailAndPasswordMiddleware(){
//这些功能始终需要
//你的店,
//已发送的操作
//这个函数有一个叫做next的特殊函数。
返回(存储、操作、NextDispatcher next)异步{
//FirebaseUser是您的用户类型。
FirebaseUser用户;
//Firebase“实例”是提供
//您可以访问FirebaseUser。这包括
//一些我们需要登录的代币。
final FirebaseAuth _auth=FirebaseAuth.instance;
如果(操作是使用mailandpassword登录){
试一试{
user=wait _auth.signin with Email and Password(
电子邮件:action.getUsername(),
密码:action.getPassword());
打印('Logged in'+user.displayName);
//这可能很难解释,至少对我来说是这样。
//如果我们登录,我们将发布一个新操作,
//
//我们还通过调用next(action)继续当前的循环。
store.dispatch(使用MailandPasswordSuccessful(用户:user))进行新登录;
}捕获(错误){
store.dispatch(使用MailandPasswordFail新登录(错误));
}
}
//在你做了你需要做的逻辑之后,
//调用此Redux内置方法,
//它将继续redux循环。
下一步(行动);
};
}
我会检查user
对象是否具有displayName
属性
通过打印
user
对象而不是user.displayName
来验证我的问题是我没有正确实例化中间件,因为在本节中我有多个中间件
List<Middleware<AppState>> createAuthMiddleware() {
print('createAuthMiddleware');
final logIn = createLogInMiddleware();
final logOut = createLogOutMiddleware();
final signUp = createSignUpMiddleware();
return [
TypedMiddleware<AppState, LogInWithGoogle>(logIn),
TypedMiddleware<AppState, LogInWithFacebook>(logIn),
TypedMiddleware<AppState, LogInEmailAndPassword>(logIn),
TypedMiddleware<AppState, CheckLogIn>(logIn),
TypedMiddleware<AppState, ForgotPassword>(logIn),
TypedMiddleware<AppState, SignUpEmailAndPassword>(signUp),
TypedMiddleware<AppState, LogOut>(logOut),
];
}
List createAuthMiddleware(){
打印('createAuthMiddleware');
最终登录=createLogInMiddleware();
最终注销=createLogOutMiddleware();
最终注册=createSignUpMiddleware();
返回[
TypeDmdlware(登录),
TypeDmdlware(登录),
TypeDmdlware(登录),
TypeDmdlware(登录),
TypeDmdlware(登录),
TypeDmdlware(注册),
类型Dmdlware(注销),
];
}