Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum ErrorCode {
UserRoomListNotEmpty, // user room list is not empty.
UserAlreadyBinding, // user already binding
UserPasswordIncorrect, // user password (for update) incorrect
UserOrPasswordIncorrect, // user or password (for login) incorrect

RecordNotFound = 500000, // record info not found

Expand Down
6 changes: 3 additions & 3 deletions src/v2/services/user/__tests__/email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ test(`${namespace} - user email not found in login`, async ava => {
() => new UserEmailService(ids(), t).login(`${v4()}@test.com`, v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand All @@ -164,7 +164,7 @@ test(`${namespace} - user email not found in login`, async ava => {
() => new UserEmailService(ids(), t).login(userEmailInfo.userEmail, v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand All @@ -182,7 +182,7 @@ test(`${namespace} - user email wrong password`, async ava => {
() => new UserEmailService(ids(), t).login(userEmailInfo.userEmail, v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserPasswordIncorrect}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand Down
6 changes: 3 additions & 3 deletions src/v2/services/user/__tests__/phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test(`${namespace} - user phone not found in login`, async ava => {
() => new UserPhoneService(ids(), t).login(randomPhoneNumber(), v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand All @@ -168,7 +168,7 @@ test(`${namespace} - user phone not found in login`, async ava => {
() => new UserPhoneService(ids(), t).login(userPhoneInfo.phoneNumber, v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand All @@ -186,7 +186,7 @@ test(`${namespace} - user phone wrong password`, async ava => {
() => new UserPhoneService(ids(), t).login(userPhoneInfo.phoneNumber, v4(), async () => ""),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.UserPasswordIncorrect}`,
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
},
);

Expand Down
8 changes: 4 additions & 4 deletions src/v2/services/user/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class UserEmailService {
const userUUIDByEmail = await this.userUUIDByEmail(email);
if (!userUUIDByEmail) {
this.logger.info("login email not found", { userEmail: { email } });
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

const user = await userDAO.findOne(
Expand All @@ -177,21 +177,21 @@ export class UserEmailService {
this.logger.info("login email not found user", {
userEmail: { email, userUUIDByEmail },
});
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

if (!user.user_password) {
this.logger.info("login email user password is null", {
userEmail: { email, userUUIDByEmail },
});
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

if (user.user_password !== password) {
this.logger.info("login email password incorrect", {
userEmail: { email, userUUIDByEmail },
});
throw new FError(ErrorCode.UserPasswordIncorrect);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

return {
Expand Down
8 changes: 4 additions & 4 deletions src/v2/services/user/phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class UserPhoneService {
const userUUIDByPhone = await this.userUUIDByPhone(phone);
if (!userUUIDByPhone) {
this.logger.info("login phone not found", { userPhone: { phone } });
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

const user = await userDAO.findOne(
Expand All @@ -176,22 +176,22 @@ export class UserPhoneService {
this.logger.info("login phone not found user", {
userPhone: { phone, userUUIDByPhone },
});
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

// User didn't set password, in this case we should not allow login with password
if (!user.user_password) {
this.logger.info("login phone user password is null", {
userPhone: { phone, userUUIDByPhone },
});
throw new FError(ErrorCode.UserNotFound);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

if (user.user_password !== password) {
this.logger.info("login phone user password incorrect", {
userPhone: { phone, userUUIDByPhone },
});
throw new FError(ErrorCode.UserPasswordIncorrect);
throw new FError(ErrorCode.UserOrPasswordIncorrect);
}

return {
Expand Down