feat(auth-service): accept undefined validUntil param

The `validUntil` parameter for `createTokenForUser` may be undefined
in some usages.
As it is easy to add handling for that here, this commit implements it.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-04 13:44:43 +01:00
parent a6734cc58f
commit de952fe3b2

View file

@ -56,7 +56,7 @@ export class AuthService {
async createTokenForUser( async createTokenForUser(
user: User, user: User,
identifier: string, identifier: string,
validUntil: TimestampMillis, validUntil: TimestampMillis | undefined,
): Promise<AuthTokenWithSecretDto> { ): Promise<AuthTokenWithSecretDto> {
user.authTokens = this.getTokensByUser(user); user.authTokens = this.getTokensByUser(user);
@ -78,7 +78,7 @@ export class AuthService {
// Tokens can only be valid for a maximum of 2 years // Tokens can only be valid for a maximum of 2 years
const maximumTokenValidity = const maximumTokenValidity =
new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000; new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000;
if (validUntil === 0 || validUntil > maximumTokenValidity) { if (!validUntil || validUntil === 0 || validUntil > maximumTokenValidity) {
token = AuthToken.create( token = AuthToken.create(
keyId, keyId,
user, user,