Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: stacked_firebase_auth
description: A service class that provides Firebase Authentication Functionality on a single api
version: 2.20.0
homepage: https://stacked.filledstacks.com/
repository: https://github.com/Stacked-Org/firebase_auth.git
repository: https://github.com/pmmucsd/stacked_firebase_auth.git
issue_tracker: https://github.com/Stacked-Org/framework/issues

environment:
Expand All @@ -13,8 +13,8 @@ dependencies:
sdk: flutter

# Firebase
firebase_core: ^2.15.0
firebase_auth: ^4.7.1
firebase_core: ^3.8.0
firebase_auth: ^5.3.3
firebase_auth_platform_interface: ^7.0.0

# Firebase Authentications
Expand All @@ -32,4 +32,4 @@ dev_dependencies:
flutter_test:
sdk: flutter

flutter:
flutter: