0
votes

Playing around with Flutter for a side project and initially set up to authenticate with email and anonymously.

Weirdly, even when our test users signed in with email, they would still get signed in anonymously when they restarted the app.

As a workaround, we just turned off anonymous users and that fixed but the app still tried to sign users in anonymously as evidenced by the output logs

[VERBOSE-2:dart_error.cc(16)] Unhandled exception: PlatformException(exception, FIRAuthErrorDomain, The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section.)

Not a major issue right now but something niggly about that.

Here's code snippet for loading up users

class Profile extends StatefulWidget {
  final userId;
  Profile({Key key, final this.userId}) : super(key: key);

  @override
  _ProfileState createState() => new _ProfileState();
}

class _ProfileState extends State<Profile> {
  FirebaseUser _user;

  logout() {

  }

  @override
  void initState() {
    FirebaseAuth.instance.currentUser().then((user) => setState(() {
          _user = user;
        }));

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final Widget bioStack = new Stack(children: [
      new Text('User ID: $_user.uid')
    ]);

    return new Column(
      children: <Widget>[bioStack, new RaisedButton(
        child: new Text('Logout'),
        onPressed: logout()
      )],
    );
  }
}
1

1 Answers

0
votes

No, I don't think so. You can get the last logged in user easily. You have to use 'async' function to do so. See the answer here it will help you to get the current Firebase user.