saveTokens method
Saves the access token and, when given, the refresh token.
Both tokens are validated before anything is written. The two writes are not atomic: if the second one fails the access token stays saved and the failure is returned.
Implementation
Future<SecurityResult<void>> saveTokens({
required String accessToken,
String? refreshToken,
}) async {
if (_isBlank(accessToken)) return _invalid('access token');
if (refreshToken != null && _isBlank(refreshToken)) {
return _invalid('refresh token');
}
final access = await saveAccessToken(accessToken);
if (access.isFailure || refreshToken == null) return access;
return saveRefreshToken(refreshToken);
}