fix: resolve login error handling issues
- Fix translation service to load locales from correct path (src/locales) - Improve login security to return generic error message for both invalid email and wrong password - Make frontend error handling generic to display backend error messages properly - Remove hardcoded string matching in favor of HTTP status code checks Fixes login flow returning raw localization keys instead of user-facing messages Fixes #2768
This commit is contained in:
1 parent
f2e2d5c2ed
commit
a03996d54b
2 files changed
+7
-1
No files matched your search
@@ -83,6 +83,7 @@ class UserService {
|
|||||||
|
|
||||||
loginUser = async (email, password) => {
|
loginUser = async (email, password) => {
|
||||||
// Check if user exists
|
// Check if user exists
|
||||||
|
try {
|
||||||
const user = await this.db.userModule.getUserByEmail(email);
|
const user = await this.db.userModule.getUserByEmail(email);
|
||||||
// Compare password
|
// Compare password
|
||||||
const match = await user.comparePassword(password);
|
const match = await user.comparePassword(password);
|
||||||
@@ -101,6 +102,11 @@ class UserService {
|
|||||||
// reset avatar image
|
// reset avatar image
|
||||||
userWithoutPassword.avatarImage = user.avatarImage;
|
userWithoutPassword.avatarImage = user.avatarImage;
|
||||||
return { user: userWithoutPassword, token };
|
return { user: userWithoutPassword, token };
|
||||||
|
} catch (error) {
|
||||||
|
// If user is not found, throw a generic authentication error for security
|
||||||
|
// Don't reveal whether user exists or password is wrong
|
||||||
|
throw this.errorService.createAuthenticationError(this.stringService.authIncorrectPassword);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
editUser = async (updates, file, currentUser) => {
|
editUser = async (updates, file, currentUser) => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class TranslationService {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.translations = {};
|
this.translations = {};
|
||||||
this._language = "en";
|
this._language = "en";
|
||||||
this.localesDir = path.join(process.cwd(), "locales");
|
this.localesDir = path.join(process.cwd(), "src", "locales");
|
||||||
}
|
}
|
||||||
|
|
||||||
get serviceName() {
|
get serviceName() {
|
||||||
|
|||||||
Reference in new issue
Block a user