Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Jul 30, 2024
1 parent 9564b35 commit 711395f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
6 changes: 5 additions & 1 deletion auth_flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# tekartik flutter recommended lints (extension over google lints and pedantic)
include: package:tekartik_lints_flutter/strict.yaml
include: package:tekartik_lints_flutter/strict.yaml

linter:
rules:
public_member_api_docs: true
1 change: 1 addition & 0 deletions auth_flutter/lib/auth_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export 'src/google_auth.dart' show GoogleAuthProvider;
/// The flutter auth service
AuthService get authServiceFlutter => auth_flutter.authService;

/// The flutter auth service
@Deprecated('Use authServiceFlutter')
AuthService get authService => authServiceFlutter;
32 changes: 24 additions & 8 deletions auth_flutter/lib/src/auth_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:tekartik_firebase_flutter/src/firebase_flutter.dart'
import 'import.dart' as common;
import 'import.dart';

/// Flutter impl
class AuthServiceFlutterImpl
with AuthServiceMixin
implements AuthServiceFlutter {
Expand All @@ -35,26 +36,32 @@ class AuthServiceFlutterImpl

AuthServiceFlutter? _firebaseAuthServiceFlutter;

/// The flutter auth service
AuthServiceFlutter get authService =>
_firebaseAuthServiceFlutter ??= AuthServiceFlutterImpl();

UserFlutterImpl? wrapUser(native.User? nativeUser) =>
nativeUser != null ? UserFlutterImpl(nativeUser) : null;
/// Wearp native user.
User? wrapUser(native.User? nativeUser) =>
nativeUser != null ? _UserFlutterImpl(nativeUser) : null;

/// Flutter impl
class AuthCredentialFlutter implements AuthCredential {
/// The native instance
final native.AuthCredential nativeInstance;

/// Constructor
AuthCredentialFlutter(this.nativeInstance);
@override
String get providerId => nativeInstance.providerId;
}

/// Flutter impl
class UserCredentialFlutter implements UserCredential {
/// The native instance
final native.UserCredential nativeInstance;
User? _user;

/// Constructor
UserCredentialFlutter(this.nativeInstance);
@override
AuthCredential get credential =>
Expand All @@ -67,10 +74,10 @@ class UserCredentialFlutter implements UserCredential {
String toString() => 'UserCredentialFlutter($user)';
}

class UserFlutterImpl implements User, UserInfoWithIdToken {
class _UserFlutterImpl implements User, UserInfoWithIdToken {
final native.User nativeInstance;

UserFlutterImpl(this.nativeInstance);
_UserFlutterImpl(this.nativeInstance);

@override
String? get displayName => nativeInstance.displayName;
Expand Down Expand Up @@ -106,14 +113,16 @@ class UserFlutterImpl implements User, UserInfoWithIdToken {
(await nativeInstance.getIdToken(forceRefresh ?? false))!;
}

/// Flutter impl
class AuthFlutterImpl with AuthMixin implements AuthFlutter {
/// The native instance
final native.FirebaseAuth nativeAuth;

StreamSubscription? onAuthStateChangedSubscription;
StreamSubscription? _onAuthStateChangedSubscription;

void _listenToCurrentUser() {
onAuthStateChangedSubscription?.cancel();
onAuthStateChangedSubscription =
_onAuthStateChangedSubscription?.cancel();
_onAuthStateChangedSubscription =
nativeAuth.authStateChanges().listen((user) {
currentUserAdd(wrapUser(user));
});
Expand All @@ -129,6 +138,7 @@ class AuthFlutterImpl with AuthMixin implements AuthFlutter {
return UserCredentialFlutter(userCredential);
}

/// Constructor
AuthFlutterImpl(this.nativeAuth) {
_listenToCurrentUser();
}
Expand All @@ -143,11 +153,12 @@ class AuthFlutterImpl with AuthMixin implements AuthFlutter {
@override
Future close(common.App? app) async {
await super.close(app);
await onAuthStateChangedSubscription?.cancel();
await _onAuthStateChangedSubscription?.cancel();
}

google_sign_in.GoogleSignIn? _googleSignIn;

/// Google only...
Future<AuthSignInResult?> nativeGoogleSignIn() async {
late native.AuthCredential credential;
_googleSignIn ??= google_sign_in.GoogleSignIn();
Expand Down Expand Up @@ -191,6 +202,7 @@ class AuthFlutterImpl with AuthMixin implements AuthFlutter {
}
}

/// Web google sign in
Future<native.UserCredential> webSignInWithGoogle() async {
// Create a new provider
var googleProvider = native.GoogleAuthProvider();
Expand Down Expand Up @@ -247,9 +259,12 @@ class AuthFlutterImpl with AuthMixin implements AuthFlutter {
String toString() => 'AuthFlutter(${nativeAuth.app.name})';
}

/// Flutter impl
class AuthSignInResultFlutter implements AuthSignInResult {
/// The native instance
final native.UserCredential nativeUserCredentials;

/// Constructor
AuthSignInResultFlutter(this.nativeUserCredentials);

@override
Expand All @@ -271,5 +286,6 @@ extension FirebaseAuthFlutterExtension on Auth {
}
}

/// Auth flutter
AuthFlutter get flutter => this as AuthFlutter;
}
7 changes: 6 additions & 1 deletion auth_flutter/lib/src/auth_flutter_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ import 'package:tekartik_firebase_auth/auth.dart';
class AuthSignInOptionsWeb implements AuthSignInOptions {
late bool _isPopup;

// Default
/// True if it is a popup
bool get isPopup => _isPopup == true;

/// True if it is a redirect
bool get isRedirect => _isPopup != true;

/// Constructor
AuthSignInOptionsWeb({bool isPopup = false, bool isRedirect = false}) {
_isPopup = !isRedirect;
}
}

/// Browser sign in result
abstract class AuthFlutter implements Auth {
/// Sign in with popup
Future<User?> googleSignIn();
}

/// Auth service for flutter
abstract class AuthServiceFlutter implements AuthService {}
15 changes: 15 additions & 0 deletions auth_flutter/lib/src/google_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ import 'import.dart';

var _debug = false; // devWarning(true);

/// Google auth provider.
abstract class GoogleAuthProvider extends AuthProvider {
/// Default constructor
factory GoogleAuthProvider() => GoogleAuthProviderImpl();

/// Native instance
native.GoogleAuthProvider get nativeAuthProvider;

/// Adds additional OAuth 2.0 scopes that you want to request (typically email)
void addScope(String scope);
}

/// Google auth provider implementation.
class GoogleAuthProviderImpl implements GoogleAuthProvider {
/// Default constructor
GoogleAuthProviderImpl() {
nativeAuthProvider = native.GoogleAuthProvider();
}

/// The native instance
@override
late native.GoogleAuthProvider nativeAuthProvider;

/// Adds additional OAuth 2.0 scopes that you want to request from the
Expand All @@ -34,9 +44,13 @@ class GoogleAuthProviderImpl implements GoogleAuthProvider {

google_sign_in.GoogleSignIn? _googleSignIn;

/// Google auth extension.
extension AuthFlutterImplGoogle on Auth {
/// Firebase native auth
native.FirebaseAuth get firebaseNativeAuth =>
(this as AuthFlutterImpl).nativeAuth;

/// Native google sign in
Future<AuthSignInResult> nativeGoogleSignIn(
GoogleAuthProvider provider) async {
late native.AuthCredential credential;
Expand Down Expand Up @@ -93,6 +107,7 @@ extension AuthFlutterImplGoogle on Auth {
}
}

/// Web google sign in
Future<AuthSignInResult> webGoogleSignIn(GoogleAuthProvider provider) async {
// Create a new provider
var googleProvider = native.GoogleAuthProvider();
Expand Down

0 comments on commit 711395f

Please sign in to comment.