Skip to content

Commit a581e9e

Browse files
committed
Add auth registration
1 parent d911224 commit a581e9e

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/firebase_ai/firebase_ai/lib/src/firebase_ai.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class FirebaseAI extends FirebasePluginPlatform {
6969
}) {
7070
app ??= Firebase.app();
7171
appCheck ??= app.getService<FirebaseAppCheck>();
72+
auth ??= app.getService<FirebaseAuth>();
7273
var instanceKey = '${app.name}::vertexai::$location';
7374

7475
if (_cachedInstances.containsKey(instanceKey)) {
@@ -102,6 +103,7 @@ class FirebaseAI extends FirebasePluginPlatform {
102103
}) {
103104
app ??= Firebase.app();
104105
appCheck ??= app.getService<FirebaseAppCheck>();
106+
auth ??= app.getService<FirebaseAuth>();
105107
var instanceKey = '${app.name}::googleai';
106108

107109
if (_cachedInstances.containsKey(instanceKey)) {

packages/firebase_ai/firebase_ai/test/firebase_vertexai_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import 'package:firebase_ai/firebase_ai.dart';
1616
import 'package:firebase_app_check/firebase_app_check.dart';
17+
import 'package:firebase_auth/firebase_auth.dart';
1718
import 'package:firebase_core/firebase_core.dart';
1819
import 'package:flutter_test/flutter_test.dart';
1920

@@ -28,6 +29,7 @@ void main() {
2829
late FirebaseApp customApp;
2930
late FirebaseApp limitTokenApp;
3031
late FirebaseAppCheck customAppCheck;
32+
late FirebaseAuth customAuth;
3133
late FirebaseAppCheck limitTokenAppCheck;
3234

3335
group('FirebaseAI Tests', () {
@@ -47,6 +49,7 @@ void main() {
4749
appCheck = FirebaseAppCheck.instance;
4850
customAppCheck = FirebaseAppCheck.instanceFor(app: customApp);
4951
limitTokenAppCheck = FirebaseAppCheck.instanceFor(app: limitTokenApp);
52+
customAuth = FirebaseAuth.instanceFor(app: customApp);
5053
});
5154

5255
test('Singleton behavior', () {
@@ -98,11 +101,18 @@ void main() {
98101

99102
test('Instance creation with auto-injected AppCheck', () {
100103
final vertexAI = FirebaseAI.vertexAI(app: customApp);
101-
104+
102105
expect(vertexAI.app, equals(customApp));
103106
expect(vertexAI.appCheck, equals(customAppCheck));
104107
});
105108

109+
test('Instance creation with auto-injected Auth', () {
110+
final vertexAI = FirebaseAI.vertexAI(app: customApp);
111+
112+
expect(vertexAI.app, equals(customApp));
113+
expect(vertexAI.auth, equals(customAuth));
114+
});
115+
106116
test('generativeModel creation with Grounding tools', () {
107117
final ai = FirebaseAI.googleAI();
108118

packages/firebase_auth/firebase_auth/lib/src/firebase_auth.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class FirebaseAuth extends FirebasePluginPlatform {
4545
required FirebaseApp app,
4646
}) {
4747
return _firebaseAuthInstances.putIfAbsent(app.name, () {
48-
return FirebaseAuth._(app: app);
48+
final instance = FirebaseAuth._(app: app);
49+
app.registerService<FirebaseAuth>(instance);
50+
return instance;
4951
});
5052
}
5153

0 commit comments

Comments
 (0)