getUserToken method
Implementation
@override
Future<String?> getUserToken() async {
final MonitoringService monitoringService = core.get<MonitoringService>();
var trace = await monitoringService.createTrace(name: 'getUserToken');
trace.start();
try {
if (!isReady) {
throw LittlefishFirebaseAuthException('AUTH_INIT_000',
'$providerName: Firebase is not initialized, $providerName cannot get user token');
}
if (kCurrentUser == null) {
throw LittlefishFirebaseAuthException('AUTH_002',
'$providerName: Current user is not available, $providerName cannot get user token');
}
logger.debug(
this,
"$providerName: Getting userId token",
);
var r = await kCurrentUser?.getIdToken();
if (r == null || r.isEmpty) {
throw LittlefishFirebaseAuthException('AUTH_003',
'$providerName: User token is not available, $providerName cannot get user token');
}
logger.info(
this,
"$providerName: Got userId token successfully",
);
return r;
} on FirebaseAuthException catch (e) {
throw _handleFirebaseAuthException(e);
} catch (e) {
if (e is LittlefishException) {
rethrow;
}
throw LittlefishFirebaseAuthException(
'AUTH_014',
'An unexpected error occurred while getting user token.',
cause: e,
);
} finally {
trace.stop();
}
}