Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
24 lines
752 B
TypeScript
24 lines
752 B
TypeScript
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { Strategy } from 'passport-local';
|
|
|
|
import { AuthService } from '../auth.service';
|
|
import { Admin } from '@database/entities/admin.entity';
|
|
|
|
@Injectable()
|
|
export class LocalStrategy extends PassportStrategy(Strategy) {
|
|
constructor(private readonly authService: AuthService) {
|
|
super({
|
|
usernameField: 'account',
|
|
passwordField: 'password',
|
|
});
|
|
}
|
|
|
|
async validate(account: string, password: string): Promise<Admin> {
|
|
const admin = await this.authService.validateUser(account, password);
|
|
if (!admin) {
|
|
throw new UnauthorizedException('账号或密码错误');
|
|
}
|
|
return admin;
|
|
}
|
|
} |