validateToken method

Future<bool> validateToken([
  1. Credentials? creds
])

Validates the AccessToken of the provided Credentials.

If none provided, checks the current credentials.

Implementation

Future<bool> validateToken([Credentials? creds]) async {
  if (creds == null) {
    Log.debug(
      'validateToken($creds) with current being: ${credentials.value}',
      '$runtimeType',
    );
  } else {
    Log.debug('validateToken($creds)', '$runtimeType');
  }

  return await WebUtils.protect(() async {
    // If [creds] are not provided, then validate the current [credentials].
    creds ??= credentials.value;

    if (creds == null) {
      return false;
    }

    try {
      await _authRepository.validateToken(creds!);
      return true;
    } on AuthorizationException {
      return false;
    }
  });
}