Skip to content

Commit

Permalink
Null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Jan 11, 2024
1 parent 9b3c6df commit 058ba66
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Shoko.Server/API/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public ActionResult ChangePassword([FromBody] string newPassword)
[HttpDelete]
public ActionResult Delete(string apikey)
{
var token = RepoFactory.AuthTokens.GetAll().FirstOrDefault(a => a.UserID == User.JMMUserID && a.DeviceName.EqualsInvariantIgnoreCase(apikey));
var token = RepoFactory.AuthTokens.GetAll().FirstOrDefault(a => a.UserID == User?.JMMUserID && a.DeviceName.EqualsInvariantIgnoreCase(apikey));
token ??= RepoFactory.AuthTokens.GetByToken(apikey);
if (User.JMMUserID != token.UserID && User.IsAdmin != 1) return Unauthorized("Cannot delete a token for another user");
if (User?.JMMUserID != token.UserID && User?.IsAdmin != 1) return Unauthorized("Cannot delete a token for another user");
RepoFactory.AuthTokens.Delete(token);
return Ok();
}
Expand Down

0 comments on commit 058ba66

Please sign in to comment.