Skip to content

Commit

Permalink
rename Auth to FirebaseAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Nov 7, 2023
1 parent 770bf3d commit b0e2c75
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 40 deletions.
2 changes: 2 additions & 0 deletions auth/lib/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export 'package:tekartik_firebase_auth/src/auth.dart'
show
Auth,
AuthService,
FirebaseAuth,
FirebaseAuthService,
UserMetadata,
UserInfo,
User,
Expand Down
26 changes: 16 additions & 10 deletions auth/lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import 'dart:async';

import 'package:tekartik_firebase/firebase.dart';

abstract class AuthService {
/// To deprecate: Use FirebaseAuthService
typedef AuthService = FirebaseAuthService;

/// To deprecate: Use FirebaseAuthService
typedef Auth = FirebaseAuth;

abstract class FirebaseAuthService {
// true if it supports listing and finding users
bool get supportsListUsers;

bool get supportsCurrentUser;

Auth auth(App app);
FirebaseAuth auth(App app);
}

/// Represents an auth provider.
Expand All @@ -33,7 +39,7 @@ abstract class AuthSignInResult {

/// Represents a Auth Database and is the entry point for all
/// Auth operations.
abstract class Auth {
abstract class FirebaseAuth {
/// Retrieves a list of users (single batch only) with a size of [maxResults]
/// and starting from the offset as specified by [pageToken].
///
Expand All @@ -49,7 +55,7 @@ abstract class Auth {
/// Gets the user data for all the users.
Future<List<UserRecord>> getUsers(List<String> uids);

/// only if [AuthService.supportsCurrentUser] is true
/// only if [FirebaseAuthService.supportsCurrentUser] is true
User? get currentUser;

/// Reload user (needed after email verification)
Expand All @@ -61,7 +67,7 @@ abstract class Auth {
/// none)
Stream<User?> get onCurrentUser;

/// only if [AuthService.supportsCurrentUser] is true.
/// only if [FirebaseAuthService.supportsCurrentUser] is true.
///
/// Credential can be null and the login happen later
Future<AuthSignInResult> signIn(AuthProvider authProvider,
Expand All @@ -83,7 +89,7 @@ abstract class UserRecord {
/// The user's custom claims object if available, typically used to define user
/// roles and propagated to an authenticated user's ID token.
///
/// This is set via [Auth.setCustomUserClaims].
/// This is set via [FirebaseAuth.setCustomUserClaims].
dynamic get customClaims;

/// Whether or not the user is disabled: true for disabled; false for enabled.
Expand All @@ -108,7 +114,7 @@ abstract class UserRecord {
/// typical when migrating from another Auth system, this will be an empty
/// string. If no password is set, this will be`null`.
///
/// This is only available when the user is obtained from [Auth.listUsers].
/// This is only available when the user is obtained from [FirebaseAuth.listUsers].
String? get passwordHash;

/// The user’s password salt (base64-encoded), only if Firebase Auth hashing
Expand All @@ -118,7 +124,7 @@ abstract class UserRecord {
/// when migrating from another Auth system, this will be an empty string.
/// If no password is set, this will be `null`.
///
/// This is only available when the user is obtained from [Auth.listUsers].
/// This is only available when the user is obtained from [FirebaseAuth.listUsers].
String? get passwordSalt;

/// The user's primary phone number or `null`.
Expand All @@ -133,7 +139,7 @@ abstract class UserRecord {
/// The date the user's tokens are valid after, formatted as a UTC string.
///
/// This is updated every time the user's refresh token are revoked either from
/// the [Auth.revokeRefreshTokens] API or from the Firebase Auth backend on big
/// the [FirebaseAuth.revokeRefreshTokens] API or from the Firebase Auth backend on big
/// account changes (password resets, password or email updates, etc).
String? get tokensValidAfterTime;

Expand Down Expand Up @@ -221,7 +227,7 @@ abstract class ListUsersResult {
}

/// Interface representing a decoded Firebase ID token, returned from the
/// [Auth.verifyIdToken] method.
/// [FirebaseAuth.verifyIdToken] method.
abstract class DecodedIdToken {
/// The uid corresponding to the user who the ID token belonged to.
String get uid;
Expand Down
9 changes: 5 additions & 4 deletions auth/lib/src/auth_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import 'package:tekartik_common_utils/stream/subject.dart';
import 'package:tekartik_firebase/firebase.dart';
import 'package:tekartik_firebase_auth/auth.dart';

mixin AuthServiceMixin implements AuthService {
mixin AuthServiceMixin implements FirebaseAuthService {
/// Most implementation need a single instance, keep it in memory!
static final _instances = <App, Auth?>{};
static final _instances = <App, FirebaseAuth?>{};

T getInstance<T extends Auth?>(App app, T Function() createIfNotFound) {
T getInstance<T extends FirebaseAuth?>(
App app, T Function() createIfNotFound) {
var instance = _instances[app] as T?;
if (instance == null) {
instance = createIfNotFound();
Expand All @@ -18,7 +19,7 @@ mixin AuthServiceMixin implements AuthService {
}
}

mixin AuthMixin implements Auth, FirebaseAppService {
mixin AuthMixin implements FirebaseAuth, FirebaseAppService {
final _currentUserSubject = Subject<User?>();

void currentUserAdd(User? user) {
Expand Down
2 changes: 1 addition & 1 deletion auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tekartik_firebase_auth
description: Firebase auth core
version: 0.9.0
version: 0.9.1

publish_to: none

Expand Down
4 changes: 2 additions & 2 deletions auth_browser/lib/auth_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export 'package:tekartik_firebase_auth_browser/src/auth_browser_facebook.dart'

export 'auth_browser_api.dart';

AuthService get authServiceBrowser => auth_browser.authService;
FirebaseAuthService get authServiceBrowser => auth_browser.authService;
@Deprecated('Use authServiceBrowser')
AuthService get authService => authServiceBrowser;
FirebaseAuthService get authService => authServiceBrowser;
4 changes: 2 additions & 2 deletions auth_browser/lib/src/auth_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AuthServiceBrowserImpl
with AuthServiceMixin
implements AuthServiceBrowser {
@override
Auth auth(common.App app) {
FirebaseAuth auth(common.App app) {
return getInstance(app, () {
assert(app is firebase_browser.AppBrowser, 'invalid firebase app type');
final appBrowser = app as firebase_browser.AppBrowser;
Expand All @@ -49,7 +49,7 @@ class AuthServiceBrowserImpl

AuthServiceBrowser? _firebaseAuthServiceBrowser;

AuthService get authService =>
FirebaseAuthService get authService =>
_firebaseAuthServiceBrowser ??= AuthServiceBrowserImpl();

class AuthProviderImpl implements AuthProvider {
Expand Down
2 changes: 1 addition & 1 deletion auth_browser/lib/src/auth_browser_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ abstract class AuthBrowser with AuthMixin {
Future<UserCredential?> signInPopup(AuthProvider authProvider);
}

abstract class AuthServiceBrowser implements AuthService {}
abstract class AuthServiceBrowser implements FirebaseAuthService {}
9 changes: 5 additions & 4 deletions auth_local/lib/auth_local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export 'package:tekartik_firebase_auth_local/src/auth_local.dart'
AuthLocalProvider,
UserRecordLocal;

AuthService get authServiceLocal => auth_local.authService;
FirebaseAuthService get authServiceLocal => auth_local.authService;
@Deprecated('Use authServiceLocal')
AuthService get authService => authServiceLocal;
FirebaseAuthService get authService => authServiceLocal;

/// For unit test
AuthService newAuthServiceLocal() => auth_local.AuthServiceLocal();
FirebaseAuthService newAuthServiceLocal() => auth_local.AuthServiceLocal();

/// Quick firestore test helper
Auth newAuthLocal() => newAuthServiceLocal().auth(newFirebaseAppLocal());
FirebaseAuth newAuthLocal() =>
newAuthServiceLocal().auth(newFirebaseAppLocal());
8 changes: 4 additions & 4 deletions auth_local/lib/src/auth_local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class UserLocal extends UserInfoLocal implements User {
bool get isAnonymous => false;
}

abstract class AuthLocal implements Auth {}
abstract class AuthLocal implements FirebaseAuth {}

class AuthLocalImpl with AuthMixin implements AuthLocal {
final AppLocal? _appLocal;
Expand Down Expand Up @@ -274,12 +274,12 @@ class DecodedIdTokenLocal implements DecodedIdToken {
DecodedIdTokenLocal({required this.uid});
}

class AuthServiceLocal with AuthServiceMixin implements AuthService {
class AuthServiceLocal with AuthServiceMixin implements FirebaseAuthService {
@override
bool get supportsListUsers => true;

@override
Auth auth(App app) {
FirebaseAuth auth(App app) {
return getInstance(app, () {
// assert(app is AppLocal, 'invalid app type - not AppLocal');
// final appLocal = app as AppLocal;
Expand All @@ -296,4 +296,4 @@ AuthServiceLocal? _authServiceLocal;
AuthServiceLocal get authServiceLocal =>
_authServiceLocal ??= AuthServiceLocal();

AuthService get authService => authServiceLocal;
FirebaseAuthService get authService => authServiceLocal;
4 changes: 2 additions & 2 deletions auth_local/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tekartik_firebase_auth_local
description: Firebase local test
version: 0.10.0
version: 0.10.1
publish_to: none

environment:
Expand All @@ -13,7 +13,7 @@ dependencies:
url: https://github.com/tekartik/firebase_auth.dart
path: auth
ref: dart3a
version: '>=0.9.0'
version: '>=0.9.1'
tekartik_firebase_local:
git:
url: https://github.com/tekartik/firebase.dart
Expand Down
4 changes: 2 additions & 2 deletions auth_rest/lib/auth_rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export 'package:tekartik_firebase_auth_rest/src/auth_rest.dart'
export 'package:tekartik_firebase_auth_rest/src/google_auth_rest.dart'
show GoogleAuthOptions;

AuthService get authServiceRest => auth_rest.authService;
FirebaseAuthService get authServiceRest => auth_rest.authService;
@Deprecated('Use authServiceRest')
AuthService get authService => authServiceRest;
FirebaseAuthService get authService => authServiceRest;

/// Build an authorization header.
String getAuthorizationHeader(String token) => 'Bearer $token';
Expand Down
10 changes: 5 additions & 5 deletions auth_rest/lib/src/auth_rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class UserRest extends UserInfoRest implements User {
}

/// Custom auth rest
abstract class AuthRest implements Auth {
abstract class AuthRest implements FirebaseAuth {
Client? get client;

/// Custom AuthRest
Expand All @@ -209,7 +209,7 @@ abstract class AuthRest implements Auth {
}

/// Rest specific helper for adding a provider.
extension AuthRestExt on Auth {
extension AuthRestExt on FirebaseAuth {
void addProvider(AuthProviderRest authProviderRest) =>
(this as AuthRest).addProviderImpl(authProviderRest);
}
Expand Down Expand Up @@ -420,12 +420,12 @@ class DecodedIdTokenLocal implements DecodedIdToken {
DecodedIdTokenLocal({required this.uid});
}

class AuthServiceRest with AuthServiceMixin implements AuthService {
class AuthServiceRest with AuthServiceMixin implements FirebaseAuthService {
@override
bool get supportsListUsers => false;

@override
Auth auth(App app) {
FirebaseAuth auth(App app) {
return getInstance(app, () {
// assert(app is AppLocal, 'invalid app type - not AppLocal');
// final appLocal = app as AppLocal;
Expand All @@ -441,7 +441,7 @@ AuthServiceRest? _authServiceRest;

AuthServiceRest get authServiceLocal => _authServiceRest ??= AuthServiceRest();

AuthService get authService => authServiceLocal;
FirebaseAuthService get authService => authServiceLocal;

class AuthAccountApi {
final String apiKey;
Expand Down
6 changes: 3 additions & 3 deletions auth_test/lib/auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bool skipConcurrentTransactionTests = false;

void run(
{required fb.Firebase firebase,
required AuthService authService,
required FirebaseAuthService authService,
String? name,
fb.AppOptions? options}) {
var app = firebase.initializeApp(name: name, options: options);
Expand All @@ -21,8 +21,8 @@ void run(
}

void runApp(
{required AuthService authService,
required Auth auth,
{required FirebaseAuthService authService,
required FirebaseAuth auth,
required fb.App app}) {
setUpAll(() async {});
group('auth', () {
Expand Down

0 comments on commit b0e2c75

Please sign in to comment.