import passport from 'passport' ; import { Module , INestApplication , } from '@nestjs/common' ; import { UserModule } from '../user/user.module' ; import { AuthService } from './auth.service' ; import { LocalRegisterStrategy , LocalLoginStrategy , } from './strategies' ; @ Module ( { imports : [ UserModule , ] , providers : [ AuthService , LocalRegisterStrategy , LocalLoginStrategy , ] , exports : [ AuthService , ] , } ) export class AuthModule { constructor ( private readonly authService ) { } public initialize ( app ) { app . use ( passport . initialize ( ) ) ; app . use ( passport . session ( ) ) ; passport . serializeUser ( ( user , done ) => done ( null , user ) ) ; passport . deserializeUser ( ( id , done ) => done ( null , id ) ) ; passport . use ( new LocalRegisterStrategy ( this . authService ) ) ; passport . use ( new LocalLoginStrategy ( this . authService ) ) ; } }