Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nextstep-backend/src/services/users_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const deleteUserById = async (id: string): Promise<UserData | null> => {
return user ? userToUserData(user) : null;
};

export const registerUser = async (username: string, password: string, email: string, authProvider: string): Promise<UserData> => {
export const registerUser = async (username: string, password: string, email: string, authProvider: string = "local"): Promise<UserData> => {
let hashedPassword: string = '';
// If registering with a password (local registration)
if (password && authProvider === 'local') {
Expand Down Expand Up @@ -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;
}
}
Expand Down
Loading