Skip to content

Commit

Permalink
Handle failed authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-rtf committed Aug 22, 2024
1 parent ce04ac5 commit f9ae5c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Morphic.Service/HttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public HttpService(Uri endpoint, IHttpServiceCredentialsProvider credentialsProv
}
catch (BadRequestException e)
{
throw e;
// OBSERVATION: in our testing, this occurred in scenarios like logging in with an invalid username/password combination (such as after changing a password online); throwing an unhandled exception would not be an appropriate response
System.Diagnostics.Debug.Assert(false, "BadRequest; exception: " + e.Message);
logger.LogError(e, "Request failed");
return null;
// throw e;
}
catch (Exception e)
{
Expand Down
8 changes: 7 additions & 1 deletion Morphic.Service/MorphicSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public override async Task OpenAsync()
// NOTE: ideally we would not re-authenticate and re-load the MorphicBars before loading the current bar (i.e. ideally we would cache this data, like we do on macOS)
if (this.CurrentCredentials is UsernameCredentials credentials)
{
await this.Authenticate(credentials, false);
var authenticateSuccess = await this.Authenticate(credentials, false);
if (authenticateSuccess == false)
{
// user could not be logged in; reverse user to null
// OBSERVATION: this is not the cleanest way to handle a failed authentication attempt; in the future, we should prompt the user to let them know that authentication failed (and why...either a busy server or a bad login credential, etc.)--and they should know they're not logged in AND they should have the opportunity to sign in (assuming the server is not busy)
this.User = null;
}
}
//
// cache our user id (so that we don't re-call "user changed" if our user doesn't actually change here)
Expand Down

0 comments on commit f9ae5c8

Please sign in to comment.