From f35eb898a1f92740aef8b9042411852a477c857d Mon Sep 17 00:00:00 2001 From: Bricks666 Date: Mon, 22 Jan 2024 00:17:14 +0300 Subject: [PATCH] fix tracking inactivated accounts --- src/auth/lib/activated/is-activated.guard.ts | 9 ++------- src/auth/services/auth/auth.service.ts | 7 ++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/auth/lib/activated/is-activated.guard.ts b/src/auth/lib/activated/is-activated.guard.ts index 2065191..b8eccca 100644 --- a/src/auth/lib/activated/is-activated.guard.ts +++ b/src/auth/lib/activated/is-activated.guard.ts @@ -1,9 +1,4 @@ -import { - CanActivate, - ExecutionContext, - ForbiddenException, - Injectable -} from '@nestjs/common'; +import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { Request } from 'express'; import { SecurityUserDto } from '@/users/dto'; @@ -31,7 +26,7 @@ export class IsActivatedGuard implements CanActivate { const user = (req as any).user as SecurityUserDto; if (!user) { - throw new ForbiddenException('User is not activated'); + return true; } return this.usersService.isActivated({ id: user.id, }); diff --git a/src/auth/services/auth/auth.service.ts b/src/auth/services/auth/auth.service.ts index 1c7553e..b1adee8 100644 --- a/src/auth/services/auth/auth.service.ts +++ b/src/auth/services/auth/auth.service.ts @@ -1,4 +1,5 @@ import { + BadRequestException, ConflictException, ForbiddenException, Injectable, @@ -76,13 +77,17 @@ export class AuthService { const user = await this.usersService.getInsecure({ email, }); + if (!user.activated) { + throw new BadRequestException('User is not activated'); + } + const isValidPassword = await compare(password, user.password); if (!isValidPassword) { throw new ForbiddenException('Incorrect password'); } - user.password = undefined; + delete user.password; const tokens = await this.#generateTokens(user);