import { PassportSerializer } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';

@Injectable()
export class ExpressSessionSerializer extends PassportSerializer {
  serializeUser(user: any, done: (err: any, user: any) => void): any {
    if (!user){
        done(new UnauthorizedException('Serialize user error'), user);
    }
    done(null, user);
  }
  deserializeUser(payload: any, done: (err: any, payload: string) => void): any {
    if (!payload){
        done(new UnauthorizedException('Deserialize user error'), payload);
        }
    done(null, payload);
  }
}