import { PassportSerializer } from '@nestjs/passport' ; import { Inject , Injectable } from '@nestjs/common' ; import { User } from '../../typeorm' ; import { Done } from '../../utils/types' ; import { AuthenticationProvider } from '../services/auth/auth' ; @ Injectable ( ) export class SessionSerializer extends PassportSerializer { constructor ( @ Inject ( 'AUTH_SERVICE' ) private readonly authService ) { super ( ) ; } serializeUser ( user , done ) { done ( null , user ) ; } async deserializeUser ( user , done ) { const userDB = await this . authService . findUser ( user . discordId ) ; return userDB ? done ( null , userDB ) : done ( null , null ) ; } }