Flutter,Redux和Firebase Auth无效参数错误

时间:2018-12-27 08:14:11

标签: firebase redux firebase-authentication flutter

我正在开发Flutter应用程序,并在项目中添加了Firebase身份验证。而且,对于Google登录来说,它运行良好,但我不知道make的工作原理。使用电子邮件和密码登录。

我按照那里的示例https://flutterbyexample.com/log-in-redux-cycle-contd

我已经添加了操作,reduce和中间件,以遵循Google登录指南,但在电子邮件和密码的情况下,会发生一些奇怪的事情。

这里是日志:

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);
  };
}

2 个答案:

答案 0 :(得分:0)

我将检查<script src="test.js" type="text/javascript"> 对象是否具有user属性。

通过打印displayName对象而不是user

进行验证

答案 1 :(得分:0)

我的问题是我没有正确实例化中间件,因为在本节中,我有多个中间件。

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),
  ];
}