Skip to content

Commit

Permalink
feat: add app and service to all firebase app product
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Sep 4, 2024
1 parent 227f5ce commit 3ed3f76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
local.*

.dart_tool/
pubspec_overrides.yaml
37 changes: 22 additions & 15 deletions auth_rest/lib/src/auth_rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ abstract class AuthRest implements FirebaseAuth {

/// Custom AuthRest
factory AuthRest(
{required FirebaseAppRest appRest,
{required AuthServiceRest authService,
required FirebaseAppRest appRest,
String? rootUrl,
String? servicePathBase}) {
return AuthRestImpl(appRest,
return AuthRestImpl(authService, appRest,
rootUrl: rootUrl, servicePathBase: servicePathBase);
}

Expand Down Expand Up @@ -300,17 +301,16 @@ class _ProviderUser {
class AuthRestImpl
with FirebaseAppProductMixin<FirebaseAuth>, AuthMixin, AuthRestMixin
implements AuthRest {
final AuthServiceRest serviceRest;
@override
Client? client;

final _providerUserController = StreamController<_ProviderUser?>.broadcast();
_ProviderUser? _currentProviderUser;

AuthSignInResultRest? signInResultRest;
final FirebaseAppRest? _appRest;
final FirebaseAppRest _appRest;

// ignore: unused_field
final App _app;
IdentityToolkitApi? _identitytoolkitApi;
String? rootUrl;
String? servicePathBase;
Expand All @@ -323,13 +323,13 @@ class AuthRestImpl
var defaultRootUrl = 'https://www.googleapis.com/';

var defaultServicePath = 'identitytoolkit/v3/relyingparty/';
return IdentityToolkitApi(_appRest!.client!,
return IdentityToolkitApi(_appRest.client!,
servicePath: servicePathBase == null
? defaultServicePath
: '$servicePathBase/$defaultServicePath',
rootUrl: rootUrl ?? defaultRootUrl);
} else {
return IdentityToolkitApi(_appRest!.client!);
return IdentityToolkitApi(_appRest.client!);
}
}();

Expand All @@ -346,14 +346,14 @@ class AuthRestImpl
}
}
// ignore: deprecated_member_use
_appRest!.client = client;
_appRest.client = client;
}

final _currentUserInitLock = Lock();

AuthRestImpl(this._app, {this.rootUrl, this.servicePathBase})
: _appRest = (_app is FirebaseAppRest ? _app : null) {
client = _appRest?.client;
AuthRestImpl(this.serviceRest, this._appRest,
{this.rootUrl, this.servicePathBase}) {
client = _appRest.client;
// Copy auth client upon connection

var firstCurrentUserCompleter = Completer<_ProviderUser?>();
Expand Down Expand Up @@ -450,7 +450,7 @@ class AuthRestImpl
client = result.client;
// Set in global too.
// ignore: deprecated_member_use
(_appRest as FirebaseAppRest).client = client;
_appRest.client = client;
signInResultRest = result;
}
return result;
Expand All @@ -469,7 +469,7 @@ class AuthRestImpl
}

@override
String toString() => _appRest?.name ?? 'local';
String toString() => _appRest.name;

@override
Future<DecodedIdToken> verifyIdToken(String idToken,
Expand All @@ -485,7 +485,7 @@ class AuthRestImpl
@override
Future<UserCredential> signInWithEmailAndPassword(
{required String email, required String password}) async {
var client = EmailPasswordLoginClient(apiKey: _appRest!.options.apiKey!);
var client = EmailPasswordLoginClient(apiKey: _appRest.options.apiKey!);
var apiV3 = identitytoolkit_v3.IdentityToolkitApi(client);
var response = await apiV3.relyingparty.verifyPassword(
identitytoolkit_v3.IdentitytoolkitRelyingpartyVerifyPasswordRequest()
Expand All @@ -512,6 +512,12 @@ class AuthRestImpl
provider: EmailPasswordAuthProviderRest(),
uid: response.localId!));
}

@override
FirebaseApp get app => _appRest;

@override
FirebaseAuthService get service => serviceRest;
}

class DecodedIdTokenLocal implements DecodedIdToken {
Expand All @@ -531,8 +537,9 @@ class AuthServiceRest
FirebaseAuth auth(App app) {
return getInstance(app, () {
assert(app is FirebaseAppRest, 'invalid app type - not AppLocal');
final appRest = app as FirebaseAppRest;
// final appLocal = app as AppLocal;
return AuthRestImpl(app);
return AuthRestImpl(this, appRest);
});
}

Expand Down
3 changes: 3 additions & 0 deletions firestore_rest/lib/src/firestore_rest_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ class FirestoreRestImpl
Future<List<CollectionReference>> listDocumentCollections(String path) async {
return _listCollections(path);
}

@override
FirebaseApp get app => appImpl;
}

class FirestoreServiceRestImpl
Expand Down
23 changes: 14 additions & 9 deletions storage_rest/lib/src/storage_rest_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class StorageRest extends Storage {
// StorageServiceRest? serviceRest,
required Client authClient}) {
return StorageRestImpl.fromAuthClient(
service: storageServiceRest, authClient: authClient);
serviceRest: storageServiceRest, authClient: authClient);
}
}

Expand All @@ -46,28 +46,27 @@ class StorageServiceRestImpl
class StorageRestImpl
with FirebaseAppProductMixin<FirebaseStorage>, StorageMixin
implements StorageRest {
late final StorageServiceRest service;
late final FirebaseAppRest? appImpl;
late final StorageServiceRest serviceRest;
late final FirebaseAppRest appRest;

Client get authClient => _authClient ??= appImpl!.client!;
Client get authClient => _authClient ??= appRest.client!;
Client? _authClient;
api.StorageApi? _storageApi;

api.StorageApi get storageApi => _storageApi ??= api.StorageApi(authClient);

StorageRestImpl(this.service, this.appImpl);
StorageRestImpl(this.serviceRest, this.appRest);
StorageRestImpl.fromAuthClient(
{required this.service, required Client authClient}) {
{required this.serviceRest, required Client authClient}) {
_authClient = authClient;
appImpl = null;
}

@override
Bucket bucket([String? name]) => BucketRest(
this,
name ??
appImpl!.options.storageBucket ??
'${appImpl!.options.projectId}.appspot.com');
appRest.options.storageBucket ??
'${appRest.options.projectId}.appspot.com');

Future<bool> fileExists(BucketRest bucket, String path) async {
try {
Expand Down Expand Up @@ -162,6 +161,12 @@ class StorageRestImpl
rethrow;
}
}

@override
FirebaseApp get app => appRest;

@override
FirebaseStorageService get service => serviceRest;
}

class GetFilesResponseRest implements GetFilesResponse {
Expand Down

0 comments on commit 3ed3f76

Please sign in to comment.