Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mason_api): login sets in-memory credentials #533

Merged
merged 1 commit into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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