Files
telegram-management-system/backend-nestjs/src/modules/auth/strategies/local.strategy.ts
你的用户名 237c7802e5
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit: Telegram Management System
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>
2025-11-04 15:37:50 +08:00

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;
}
}