Skip to content

Commit

Permalink
fix tracking inactivated accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bricks666 committed Jan 27, 2024
1 parent ab847a5 commit f35eb89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/auth/lib/activated/is-activated.guard.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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, });
Expand Down
7 changes: 6 additions & 1 deletion src/auth/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
BadRequestException,
ConflictException,
ForbiddenException,
Injectable,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit f35eb89

Please sign in to comment.