From a45377303b1c86f7814559fd3268b7e049bd16f2 Mon Sep 17 00:00:00 2001 From: Tal Jacob Date: Mon, 2 Jun 2025 06:38:13 +0300 Subject: [PATCH] Set Local To Be Default AuthProvider And Fix Login Password Comparison Signed-off-by: Tal Jacob --- nextstep-backend/src/services/users_service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nextstep-backend/src/services/users_service.ts b/nextstep-backend/src/services/users_service.ts index 266d871..19824a5 100644 --- a/nextstep-backend/src/services/users_service.ts +++ b/nextstep-backend/src/services/users_service.ts @@ -49,7 +49,7 @@ export const deleteUserById = async (id: string): Promise => { return user ? userToUserData(user) : null; }; -export const registerUser = async (username: string, password: string, email: string, authProvider: string): Promise => { +export const registerUser = async (username: string, password: string, email: string, authProvider: string = "local"): Promise => { let hashedPassword: string = ''; // If registering with a password (local registration) if (password && authProvider === 'local') { @@ -102,14 +102,14 @@ export const loginUserGoogle = async (email: string, authProvider: string, name: return {...tokens, userId: user.id, username: user.username, imageFilename: user.imageFilename} } -export const loginUser = async (email: string, password: string, authProvider?: string): Promise<{ accessToken: string, refreshToken: string, userId: string, username: string, imageFilename?: string } | null> => { +export const loginUser = async (email: string, password: string, authProvider: string = "local"): Promise<{ accessToken: string, refreshToken: string, userId: string, username: string, imageFilename?: string } | null> => { const user = await getIUserByEmail(email); if (!user) { return null; } // Local login (with password) if (authProvider === 'local') { - if ((await bcrypt.compare(password, user.password))) { + if (!(await bcrypt.compare(password, user.password))) { return null; } }