checkIfSignedInAndLoginAnonymouslyIfNot method

  1. @override
Future<Either<AuthServiceSignInFailure, Unit>> checkIfSignedInAndLoginAnonymouslyIfNot()
override

Implementation

@override
Future<Either<AuthServiceSignInFailure, Unit>> checkIfSignedInAndLoginAnonymouslyIfNot() async {
  try {
    if (AppConfigBase.devOnlyUid.isNotEmpty || AppConfigBase.devOnlyAutoGenerateNewUser) {
      await signInWithDevOnly();
      // await refreshCurrentUser();
      return right(unit);
    }

    // Login anonymously if not
    if (_fbAuth.currentUser == null) {
      logd('AuthService: LOGGING IN ANONYMOUSLY');

      // logd('AuthService: ${AppConfigBase.backendRegion}');
      // logd('AuthService: ${AppConfigBase.doUseBackendEmulator}');
      // logd('AuthService: ${AppConfigBase.backendEmulatorRemoteAddress}');
      // logd('AuthService: ${_fbFunctions.app.options.asMap}');
      // logd('AuthService: ${_fbFunctions.app.options.appId}');
      // logd('AuthService: ${_fbFunctions.app.name}');

      // await _fbAuth.signInAnonymously();

      var result = await retryIt(() async {
        return await authCallable.call({
          'action': 'loginAnonymously',
          'timezone': (await FlutterTimezone.getLocalTimezone()).identifier,
        });
      }, maxAttempts: 8);

      final String token = result.data['token'];

      await retryIt(
        () async => await _fbAuth.signInWithCustomToken(token),
        maxAttempts: 8,
      );
    }
    return right(unit);
  } catch (e) {
    loge(e);
    return left(AuthServiceSignInFailure.unexpected);
  }
}