Skip to content

Commit

Permalink
fix(mason_api): login sets in-memory credentials (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Oct 6, 2022
1 parent 1f9ffef commit 4631d95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/mason_api/lib/src/mason_api.dart
Expand Up @@ -175,6 +175,8 @@ class MasonApi {
throw MasonApiLoginFailure(message: '$error');
}

_credentials = credentials;

try {
return _currentUser = credentials.toUser();
} catch (error) {
Expand All @@ -187,14 +189,15 @@ class MasonApi {

/// Publish universal [bundle] to remote registry.
Future<void> publish({required List<int> bundle}) async {
if (_credentials == null) {
var credentials = _credentials;

if (credentials == null) {
throw const MasonApiPublishFailure(
message:
'''User not found. Please make sure you are logged in and try again.''',
);
}

var credentials = _credentials!;
if (credentials.areExpired) {
try {
credentials = await _refresh();
Expand Down
14 changes: 14 additions & 0 deletions packages/mason_api/test/src/mason_api_test.dart
Expand Up @@ -330,6 +330,20 @@ void main() {
credentials.expiresAt.difference(DateTime.now()).inSeconds,
closeTo(42, 1),
);

try {
await masonApi.publish(bundle: <int>[]);
fail('should throw');
} on MasonApiPublishFailure catch (error) {
expect(
error.message,
isNot(
equals(
'''User not found. Please make sure you are logged in and try again.''',
),
),
);
}
});
});

Expand Down

0 comments on commit 4631d95

Please sign in to comment.