refactor(core): enhance User and RefreshToken domain models
This commit is contained in:
@@ -5,7 +5,8 @@ public sealed class RefreshToken : Entity
|
||||
public string Token { get; init; } = string.Empty;
|
||||
public DateTimeOffset ExpiresAt { get; init; }
|
||||
public Guid UserId { get; init; }
|
||||
public User User { get; init; } = null!;
|
||||
public User? User { get; init; }
|
||||
public bool Revoked { get; set; }
|
||||
|
||||
private RefreshToken()
|
||||
{
|
||||
@@ -20,4 +21,27 @@ public sealed class RefreshToken : Entity
|
||||
ExpiresAt = expiresAt,
|
||||
};
|
||||
}
|
||||
|
||||
public static RefreshToken From(User user, string token, DateTimeOffset expiresAt)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(user);
|
||||
|
||||
return new()
|
||||
{
|
||||
User = user,
|
||||
UserId = user.Id,
|
||||
Token = token,
|
||||
ExpiresAt = expiresAt,
|
||||
};
|
||||
}
|
||||
|
||||
public void Revoke()
|
||||
{
|
||||
Revoked = true;
|
||||
}
|
||||
|
||||
public bool IsExpired(DateTimeOffset now)
|
||||
{
|
||||
return now >= ExpiresAt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user