Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
123456789101112131415161718192021222324import { Injectable, UnauthorizedException } from '@nestjs/common';import { PassportStrategy } from '@nestjs/passport';import { Strategy } from 'passport-local';import type { PublicUser } from '../domain/models';import { AuthService } from './auth.service';
// The built-in username/password provider. Its Passport strategy name is// 'local'; AuthController runs AuthGuard('local') on POST /api/auth/login/local.// validate()'s return value becomes req.user for that request.@Injectable()export class LocalStrategy extends PassportStrategy(Strategy, 'local') { constructor(private readonly auth: AuthService) { // passport-local defaults to fields named 'username'/'password' - matches // our LoginDto. super(); }
async validate(username: string, password: string): Promise<PublicUser> { const user = await this.auth.validateCredentials(username, password); if (!user) throw new UnauthorizedException('Invalid username or password'); return user; }}