Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
fix: Change login method user/pass => email/pass
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis-Bernard <alexisbernard34310@gmail.com>
  • Loading branch information
alexis-ascoz committed May 10, 2022
1 parent 57c448c commit 7c45027
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class AuthService {
private readonly tokenService: TokensService,
) {}

async validateUser(username: string, password: string): Promise<any> {
const user = await this.usersService.findOneByUsername(username);
async validateUser(email: string, password: string): Promise<any> {
const user = await this.usersService.findOneByEmail(email);

if (await this.cryptoService.compareString(password, user.password)) {
return user;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/dto/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IsString } from 'class-validator';

export class LoginDto {
@IsString()
username: string;
email: string;

@IsString()
password: string;
Expand Down
6 changes: 3 additions & 3 deletions src/auth/local.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { AuthService } from './auth.service';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super();
super({ usernameField: 'email' });
}

async validate(username: string, password: string): Promise<any> {
const user = await this.authService.validateUser(username, password);
async validate(email: string, password: string): Promise<any> {
const user = await this.authService.validateUser(email, password);
if (!user) {
throw new UnauthorizedException();
}
Expand Down
10 changes: 5 additions & 5 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export class UsersService {
}
}

async findOneByUsername(username: string) {
const user = await User.findOne({ where: { username } });
async findOneByEmail(email: string) {
const user = await User.findOne({ where: { email } });

if (user) {
return user;
} else {
if (!user) {
throw new NotFoundException();
}

return user;
}

async update(id: number, updateUserDto: UpdateUserDto) {
Expand Down

0 comments on commit 7c45027

Please sign in to comment.