From 093f6f5f789d58d54f325fcf02fbd1ab3cf09a95 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Sat, 5 Dec 2020 12:59:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20UserNotFoundOrRefreshTokenCountI?= =?UTF-8?q?nvalidError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #12 --- src/errors/AuthError.ts | 11 +++++++++++ src/models/creation/RefreshAuth.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/errors/AuthError.ts b/src/errors/AuthError.ts index cdaa870..e95670d 100644 --- a/src/errors/AuthError.ts +++ b/src/errors/AuthError.ts @@ -87,4 +87,15 @@ export class JwtNotProvidedError extends NotAcceptableError { @IsString() message = "no jwt token was provided" +} + +/** + * Error to thow when user was not found or refresh token count was invalid + */ +export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError { + @IsString() + name = "UserNotFoundOrRefreshTokenCountInvalidError" + + @IsString() + message = "user was not found or refresh token count was invalid" } \ No newline at end of file diff --git a/src/models/creation/RefreshAuth.ts b/src/models/creation/RefreshAuth.ts index 16233c4..97e5e4e 100644 --- a/src/models/creation/RefreshAuth.ts +++ b/src/models/creation/RefreshAuth.ts @@ -1,7 +1,7 @@ import { IsString } from 'class-validator'; import * as jsonwebtoken from 'jsonwebtoken'; import { getConnectionManager } from 'typeorm'; -import { IllegalJWTError, JwtNotProvidedError, UserNotFoundError } from '../../errors/AuthError'; +import { IllegalJWTError, JwtNotProvidedError, UserNotFoundOrRefreshTokenCountInvalidError } from '../../errors/AuthError'; import { Auth } from '../entities/Auth'; import { User } from '../entities/User'; @@ -22,7 +22,7 @@ export class RefreshAuth { } const found_users = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"], refreshTokenCount: decoded["refreshtokencount"] }); if (!found_users) { - throw new UserNotFoundError() + throw new UserNotFoundOrRefreshTokenCountInvalidError() } else { const found_user = found_users[0] delete found_user.password;