Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Firebase Auth #22

Closed
mattbara opened this issue Aug 10, 2020 · 3 comments
Closed

Support Firebase Auth #22

mattbara opened this issue Aug 10, 2020 · 3 comments

Comments

@mattbara
Copy link

mattbara commented Aug 10, 2020

Hey guys, could you provide a version of your dependency to be used with Firebase Auth?
I'm using this code for Google SignIn and signout, but FB has different classes and methods and I'm not sure how to integrate with flutter.
Sorry, I've started with Flutter and Dart only for the past 4 weeks.

class AuthService {
  final FirebaseAuth _auth = FirebaseAuth.instance;
  final GoogleSignIn _googleSignIn = new GoogleSignIn();

  // Create user object based on FirebaseUser
  User _userFromFirebaseUser(FirebaseUser user) {
    return user != null ? User(uid: user.uid) : null;
  }

  // Auth change user stream
  Stream<User> get user {
    return _auth.onAuthStateChanged.map(
        _userFromFirebaseUser);
  }

  // SignIn with Facebook
  Future signInFacebook() async {}

  // SignIn with Google
  Future signInGoogle() async {
    GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();

    GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;

    AuthCredential credential = GoogleAuthProvider.getCredential(
        idToken: googleSignInAuthentication.idToken,
        accessToken: googleSignInAuthentication.accessToken);

    try {
      AuthResult result = (await _auth.signInWithCredential(credential));
      FirebaseUser user = result.user;
      return _userFromFirebaseUser(user);
    } catch (e) {
      print(e.toString());
      return null;
    }
  }

  // SignOut
  Future signOut() async {
    try {
      return await _auth.signOut();
    } catch (e) {
      print(e.toString());
      return null;
    }
  }
}
@greymag
Copy link
Contributor

greymag commented Aug 10, 2020

Hey!
Check out this issue #16, does it resolve your problem?

@mattbara
Copy link
Author

@greymag

Hey!
Check out this issue #16, does it resolve your problem?

Guys, you are superstars.
Your dependency and your prompt answers to my Firebase question have solved my FB problem in 1hour.
I've been trying to use other flutter FB dependencies and all f***ing failed.
Love it love it love it. Thanks a lot!

@greymag
Copy link
Contributor

greymag commented Aug 10, 2020

Glad to hear it =))

@greymag greymag closed this as completed Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants