nestjs_auth/src/auth/guards/local.strategy.ts
2022-09-12 14:59:33 +09:00

25 lines
808 B
TypeScript

/* eslint-disable prettier/prettier */
import { Strategy } from 'passport-local'
import { PassportStrategy } from '@nestjs/passport'
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { AuthService } from '../auth.service'
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
//super()
//If you want to check user authenticate with custom column like 'email', try pass it.
super({ usernameField: process.env.AUTH_USERNAME_FIELD })
}
//Login인증용
async validate(email: string, password: string): Promise<any> {
try {
return await this.authService.validateUser(email, password)
} catch (e) {
console.log(e)
throw new UnauthorizedException(e.message)
}
}
}