Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/src/firebase_authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FirebaseAuthenticationService {
final Logger? log;

final firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
GoogleSignIn? _googleSignIn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of going to a nullable GoogleSignIn object and not using late?


FirebaseAuthenticationService({
@Deprecated(
Expand All @@ -35,7 +35,7 @@ class FirebaseAuthenticationService {
Future<UserCredential> _signInWithCredential(
AuthCredential credential,
) async {
return firebaseAuth.signInWithCredential(credential);
return await firebaseAuth.signInWithCredential(credential);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do we need to await here if the calling function should be awaiting the future?

}

/// Returns the current logged in Firebase User
Expand Down Expand Up @@ -77,7 +77,7 @@ class FirebaseAuthenticationService {
/// - iOS
/// - Web
Future<FirebaseAuthenticationResult> signInWithGoogle(
{String? webLoginHint}) async {
{String? webLoginHint, List<String>? scopes}) async {
try {
UserCredential userCredential;

Expand All @@ -87,7 +87,7 @@ class FirebaseAuthenticationService {
GoogleAuthProvider googleProvider = GoogleAuthProvider();
googleProvider.setCustomParameters(
{'login_hint': webLoginHint ?? '[email protected]'});

(scopes ?? []).forEach(googleProvider.addScope);
userCredential = await FirebaseAuth.instance.signInWithPopup(
googleProvider,
);
Expand All @@ -96,8 +96,9 @@ class FirebaseAuthenticationService {
/// On native platforms, a 3rd party library, like GoogleSignIn, is
/// required to trigger the authentication flow.
else {
_googleSignIn = GoogleSignIn(scopes: scopes ?? []);
final GoogleSignInAccount? googleSignInAccount =
await _googleSignIn.signIn();
await _googleSignIn!.signIn();
if (googleSignInAccount == null) {
log?.i('Process is canceled by the user');
return FirebaseAuthenticationResult.error(
Expand Down Expand Up @@ -125,6 +126,7 @@ class FirebaseAuthenticationService {
return FirebaseAuthenticationResult(
user: userCredential.user,
additionalUserInfo: userCredential.additionalUserInfo,
oAuthAccessToken: userCredential.credential?.accessToken,
);
} on FirebaseAuthException catch (e) {
log?.e(e);
Expand Down Expand Up @@ -510,7 +512,7 @@ class FirebaseAuthenticationService {
try {
_clearPendingData();
await firebaseAuth.signOut();
await _googleSignIn.signOut();
await _googleSignIn?.signOut();
await FacebookAuth.instance.logOut();
} catch (e) {
log?.e('Could not sign out of social account. $e');
Expand Down Expand Up @@ -597,17 +599,20 @@ class FirebaseAuthenticationResult {

/// Firebase additional user information
final AdditionalUserInfo? additionalUserInfo;
final String? oAuthAccessToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition here.


/// Contains the error message for the request
final String? errorMessage;
final String? exceptionCode;

FirebaseAuthenticationResult({this.user, this.additionalUserInfo})
FirebaseAuthenticationResult(
{this.user, this.additionalUserInfo, this.oAuthAccessToken})
: errorMessage = null,
exceptionCode = null;

FirebaseAuthenticationResult.error({this.errorMessage, this.exceptionCode})
: user = null,
oAuthAccessToken = null,
additionalUserInfo = null;

/// Returns true if the response has an error associated with it
Expand Down