import { NextFunction , Request , Response } from 'express' ; import { CreateUserDto } from '@dtos/users.dto' ; import { RequestWithUser } from '@interfaces/auth.interface' ; import { User } from '@interfaces/users.interface' ; import AuthService from '@services/auth.service' ; class AuthController { public authService = new AuthService ( ) ; public signUp = async ( req , res , next ) : Promise < void > => { try { const userData = req . body ; const signUpUserData = await this . authService . signup ( userData ) ; res . status ( 201 ) . json ( { data : signUpUserData , message : 'signup' } ) ; } catch ( error ) { next ( error ) ; } } ; public logIn = async ( req , res , next ) : Promise < void > => { try { const userData = req . body ; const { cookie , findUser } = await this . authService . login ( userData ) ; res . setHeader ( 'Set-Cookie' , [ cookie ] ) ; res . status ( 200 ) . json ( { data : findUser , message : 'login' } ) ; } catch ( error ) { next ( error ) ; } } ; public logOut = async ( req , res , next ) : Promise < void > => { try { const userData = req . user ; const logOutUserData = await this . authService . logout ( userData ) ; res . setHeader ( 'Set-Cookie' , [ 'Authorization=; Max-age=0' ] ) ; res . status ( 200 ) . json ( { data : logOutUserData , message : 'logout' } ) ; } catch ( error ) { next ( error ) ; } } ; } export default AuthController ;