1- import jwt from ' jsonwebtoken' ;
2- import bcrypt from ' bcrypt' ;
3- import { LoginPayload , RegisterPayload } from ' ./auth.validation' ;
4- import { AuthRepository } from ' ./auth.repository' ;
5- import { env } from ' config/env' ;
6- import { BadRequestError } from ' errors/bad-request.error' ;
7- import { CookieOptions } from ' express' ;
8- import { User } from ' users/users.model' ;
1+ import jwt from " jsonwebtoken" ;
2+ import bcrypt from " bcrypt" ;
3+ import { LoginPayload , RegisterPayload } from " ./auth.validation" ;
4+ import { AuthRepository } from " ./auth.repository" ;
5+ import { env } from " config/env" ;
6+ import { BadRequestError } from " errors/bad-request.error" ;
7+ import { CookieOptions } from " express" ;
8+ import { User } from " users/users.model" ;
99
1010export class AuthService {
1111 private authRepository = new AuthRepository ( ) ;
@@ -14,15 +14,15 @@ export class AuthService {
1414 // Check if email already exists
1515 const foundUser = await this . authRepository . findUserByEmail ( payload . email ) ;
1616 if ( foundUser ) {
17- throw new BadRequestError ( ' User with that email already exists' ) ;
17+ throw new BadRequestError ( " User with that email already exists" ) ;
1818 }
1919
2020 const user = await this . authRepository . createUser ( {
2121 ...payload ,
2222 password : await bcrypt . hash ( payload . password , 10 ) , // Hash password
2323 } ) ;
2424 if ( ! user ) {
25- throw new BadRequestError ( ' Failed to create user' ) ;
25+ throw new BadRequestError ( " Failed to create user" ) ;
2626 }
2727
2828 return this . removePassword ( user ) ;
@@ -31,12 +31,12 @@ export class AuthService {
3131 public async login ( payload : LoginPayload ) {
3232 const user = await this . authRepository . findUserByEmail ( payload . email ) ;
3333 if ( ! user ) {
34- throw new BadRequestError ( ' Invalid email or password' ) ;
34+ throw new BadRequestError ( " Invalid email or password" ) ;
3535 }
3636
3737 const isPasswordCorrect = await bcrypt . compare ( payload . password , user . password ) ;
3838 if ( ! isPasswordCorrect ) {
39- throw new BadRequestError ( ' Invalid email or password' ) ;
39+ throw new BadRequestError ( " Invalid email or password" ) ;
4040 }
4141
4242 return this . removePassword ( user ) ;
@@ -55,13 +55,13 @@ export class AuthService {
5555 return {
5656 maxAge : 5 * 60 * 60 * 1000 , // 5 hours
5757 httpOnly : true ,
58- sameSite : ' lax' ,
59- secure : process . env . NODE_ENV === ' production' ,
58+ sameSite : " lax" ,
59+ secure : process . env . NODE_ENV === " production" ,
6060 } ;
6161 }
6262
6363 private removePassword ( user : User ) {
64- const { password, ...userWithoutPassword } = user ;
64+ const { password : _password , ...userWithoutPassword } = user ;
6565 return userWithoutPassword ;
6666 }
6767}
0 commit comments