Skip to content

Commit

Permalink
fix: remove revoked token
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Oct 25, 2023
1 parent c40505d commit bd970c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion App/Modules/Users/API/V1/UserMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public static UserPrincipalResp ToResp(this UserPrincipal userPrincipal)
=> new(userPrincipal.Id, userPrincipal.Record.Username);

public static UserResp ToResp(this User user)
=> new(user.Principal.ToResp(), user.Tokens.Select(x => x.ToResp()));
=> new(user.Principal.ToResp(), user
.Tokens
.Where(x => !x.Record.Revoked)
.Select(x => x.ToResp()));

public static UserRecord ToRecord(this CreateUserReq req)
{
Expand Down
2 changes: 1 addition & 1 deletion App/Modules/Users/Data/TokenRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task<Result<TokenPrincipal>> Create(string userId, string token, To
.FirstOrDefaultAsync();
if (v1 == null) return (Unit?)null;

var v2 = v1 with { Revoked = true };
var v2 = v1 with { Revoked = true, User = null! };
var updated = this._db.Tokens.Update(v2);
await this._db.SaveChangesAsync();
return new Unit();
Expand Down

0 comments on commit bd970c9

Please sign in to comment.