add email account validation

This commit is contained in:
andres
2023-06-13 01:39:33 +02:00
parent 59b4eb582e
commit 6c62d87ee6
40 changed files with 578 additions and 6453 deletions

View File

@@ -1,21 +1,19 @@
import { Inject, Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { AppSettings } from '../../../settings/app-settings';
import { Inject, Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from 'passport-jwt'
import { AppSettings } from '../../../settings/app-settings'
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
@Inject(AppSettings.name) private readonly appSettings: AppSettings,
) {
constructor(@Inject(AppSettings.name) private readonly appSettings: AppSettings) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: true,
secretOrKey: appSettings.auth.ACCESS_JWT_SECRET_KEY,
});
})
}
async validate(payload: any) {
return { userId: payload.userId };
return { userId: payload.userId }
}
}

View File

@@ -1,21 +1,21 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { AuthService } from '../auth.service';
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy } from 'passport-local'
import { AuthService } from '../auth.service'
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({
usernameField: 'login',
});
usernameField: 'email',
})
}
async validate(login: string, password: string): Promise<any> {
const user = await this.authService.checkCredentials(login, password);
async validate(email: string, password: string): Promise<any> {
const user = await this.authService.checkCredentials(email, password)
if (user.resultCode === 1) {
throw new UnauthorizedException();
throw new UnauthorizedException()
}
return user;
return user
}
}