Skip to content

Commit

Permalink
Fix asynchronity of GenerateMagicLink
Browse files Browse the repository at this point in the history
  • Loading branch information
duckth committed Nov 26, 2024
1 parent 9134cb4 commit c60bbf7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public async Task SendMagicLinkEmail(string email, LoginType loginType)
// Should not throw error to prevent showing a malicious user if an email is already registered
return;
}
var magicLinkTokenHash = _tokenServiceV2.GenerateMagicLink(user);
var magicLinkTokenHash = await _tokenServiceV2.GenerateMagicLink(user);
await _emailServiceV2.SendMagicLink(user, magicLinkTokenHash, loginType);
}

Expand Down
2 changes: 1 addition & 1 deletion coffeecard/CoffeeCard.Library/Services/v2/ITokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CoffeeCard.Library.Services.v2
{
public interface ITokenService
{
string GenerateMagicLink(User user);
Task<string> GenerateMagicLink(User user);
Task<string> GenerateRefreshTokenAsync(User user);
Task<Token> GetValidTokenByHashAsync(string tokenString);
}
Expand Down
4 changes: 2 additions & 2 deletions coffeecard/CoffeeCard.Library/Services/v2/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public TokenService(CoffeeCardContext context, IHashService hashService)
_hashService = hashService;
}

public string GenerateMagicLink(User user)
public async Task<string> GenerateMagicLink(User user)
{
var guid = Guid.NewGuid().ToString();
var magicLinkToken = new Token(guid, TokenType.MagicLink);

user.Tokens.Add(magicLinkToken);
_context.SaveChangesAsync();
await _context.SaveChangesAsync();
return magicLinkToken.TokenHash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task GenerateMagicLink_ReturnsLinkWithValidTokenForUser()
var tokenService = new TokenService(context, Mock.Of<IHashService>());

// Act
var result = tokenService.GenerateMagicLink(user);
var result = await tokenService.GenerateMagicLink(user);

// Assert
Assert.NotNull(result);
Expand Down

0 comments on commit c60bbf7

Please sign in to comment.