mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2026-01-07 12:34:33 +00:00
add email account validation
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user