LogIn Redux Cycle

Let's wire up a button in our app that logs in a user with Firebase.

1. Add a new auth_actions file.

2. Add relevant actions:

  1. // actions/auth_actions.dart
  2. import 'package:firebase_auth/firebase_auth.dart';
  3. // gives us access to `@required`
  4. import 'package:flutter/foundation.dart';
  5. class LogIn {}
  6. class LogInSuccessful {
  7. final FirebaseUser user;
  8. LogInSuccessful({ @required this.user});
  9. @override
  10. String toString() {
  11. return 'LogIn{user: $user}';
  12. }
  13. }
  14. class LogInFail {
  15. final dynamic error;
  16. LogInFail(this.error);
  17. @override
  18. String toString() {
  19. return 'LogIn{There was an error loggin in: $error}';
  20. }
  21. }
  22. class LogOut {}
  23. class LogOutSuccessful {
  24. LogOutSuccessful();
  25. @override
  26. String toString() {
  27. return 'LogOut{user: null}';
  28. }
  29. }

These are our basic actions. From here, we need to write our first middleware. That takes a bit of an aside, and then we'll return to our Redux cycle.