- Backend: NestJS with Docker - Frontend: Next.js with Docker - Nginx configuration for reverse proxy - PostgreSQL setup - Docker compose for orchestration - Development environment configuration
20 lines
722 B
TypeScript
20 lines
722 B
TypeScript
// backend/src/modules/auth/strategies/local.strategy.ts
|
|
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({ usernameField: 'email' }); // Use 'email' instead of 'username'
|
|
}
|
|
|
|
async validate(email: string, password: string): Promise<any> {
|
|
const user = await this.authService.validateUser(email, password);
|
|
if (!user) {
|
|
throw new UnauthorizedException('Invalid credentials');
|
|
}
|
|
return user;
|
|
}
|
|
} |