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
5 changes: 5 additions & 0 deletions lib/src/services/yust_auth_service_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class YustAuthService {
final Yust _yust;
final ServiceAccountCredentials? _credentials;

/// Resolves once the service is ready. On Dart there is nothing async to
/// wait for, so this is always already completed — kept here to match the
/// Flutter-side API used in [Yust.initialize].
final Future<void> ready = Future.value();

/// The Firebase Auth ID (uid) used to generate tokens for backend-to-backend
/// API calls. When set, [getJWTToken] signs in as this user via a custom
/// token exchange instead of throwing [UnsupportedError].
Expand Down
18 changes: 12 additions & 6 deletions lib/src/services/yust_auth_service_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ class YustAuthService {
late final FirebaseAuth _fireAuth;
late final Yust _yust;

/// Resolves once any emulator wiring has been applied. Callers that perform
/// auth operations during initialization must await this — `useAuthEmulator`
/// returns a Future that the constructor cannot await, and on web the
/// underlying JS `connectAuthEmulator` does not take effect synchronously.
final Future<void> ready;

YustAuthService(
Yust yust, {
String? emulatorAddress,
ServiceAccountCredentials? credentials,
String? backendAuthId,
}) : _fireAuth = FirebaseAuth.instance,
_yust = yust {
if (emulatorAddress != null) {
_fireAuth.useAuthEmulator(emulatorAddress, 9099);
}
}) : ready = emulatorAddress != null
? FirebaseAuth.instance.useAuthEmulator(emulatorAddress, 9099)
: Future.value() {
_fireAuth = FirebaseAuth.instance;
_yust = yust;
}

YustAuthService.mocked(Yust yust) {
YustAuthService.mocked(Yust yust) : ready = Future.value() {
throw UnsupportedError('Not supported in Flutter Environment');
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/services/yust_auth_service_mocked.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import 'yust_auth_service.dart';
class YustAuthServiceMocked implements YustAuthService {
final Yust _yust;

@override
final Future<void> ready = Future.value();

YustAuthServiceMocked(Yust yust) : _yust = yust;

@override
Expand Down
3 changes: 3 additions & 0 deletions lib/src/yust.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ class Yust {
credentials: credentials,
backendAuthId: backendAuthId,
);
// On web, `useAuthEmulator` is async — sign-ins started before it
// resolves will hit production endpoints.
await Yust.authService.ready;
Yust.fileService = YustFileService(
authClient: authClient,
emulatorAddress: emulatorAddress,
Expand Down