oa_based/src/modules/auth/strategies/local.strategy.ts

25 lines
645 B
TypeScript
Raw Normal View History

2024-02-28 08:32:35 +08:00
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy } from 'passport-local'
import { AuthStrategy } from '../auth.constant'
import { AuthService } from '../auth.service'
@Injectable()
export class LocalStrategy extends PassportStrategy(
Strategy,
AuthStrategy.LOCAL,
) {
constructor(private authService: AuthService) {
super({
usernameField: 'credential',
passwordField: 'password',
})
}
async validate(username: string, password: string): Promise<any> {
const user = await this.authService.validateUser(username, password)
return user
}
}