-
Notifications
You must be signed in to change notification settings - Fork 26
fix: resolve duplicate error messages on login failure #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -207,80 +207,113 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| .userLogoutPreviousSession( | ||||||||||||||||||||||||||||||||||||||||||||||
| this.loginForm.controls.userName.value, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .subscribe((userlogoutPreviousSession: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (userlogoutPreviousSession.statusCode === 200) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.authService | ||||||||||||||||||||||||||||||||||||||||||||||
| .login( | ||||||||||||||||||||||||||||||||||||||||||||||
| this.loginForm.controls.userName.value, | ||||||||||||||||||||||||||||||||||||||||||||||
| encryptPassword, | ||||||||||||||||||||||||||||||||||||||||||||||
| true, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.enableCaptcha | ||||||||||||||||||||||||||||||||||||||||||||||
| ? this.captchaToken | ||||||||||||||||||||||||||||||||||||||||||||||
| : undefined, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .subscribe((userLoggedIn: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (userLoggedIn.statusCode === 200) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (userLoggedIn?.data?.previlegeObj[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.sessionstorage.setItem( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'loginDataResponse', | ||||||||||||||||||||||||||||||||||||||||||||||
| JSON.stringify(userLoggedIn.data), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.trackingService.setUserId( | ||||||||||||||||||||||||||||||||||||||||||||||
| userLoggedIn.data.userID, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.authService.sessionExpiredHandled = | ||||||||||||||||||||||||||||||||||||||||||||||
| false; | ||||||||||||||||||||||||||||||||||||||||||||||
| this.sessionstorage.setItem( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'loginDataResponse', | ||||||||||||||||||||||||||||||||||||||||||||||
| JSON.stringify(userLoggedIn.data), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.getServicesAuthdetails( | ||||||||||||||||||||||||||||||||||||||||||||||
| userLoggedIn.data, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'Seems you are logged in from somewhere else, Logout from there & try back in.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 'error', | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert( | ||||||||||||||||||||||||||||||||||||||||||||||
| userLoggedIn.errorMessage, | ||||||||||||||||||||||||||||||||||||||||||||||
| 'error', | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert( | ||||||||||||||||||||||||||||||||||||||||||||||
| userlogoutPreviousSession.errorMessage, | ||||||||||||||||||||||||||||||||||||||||||||||
| 'error', | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| .subscribe( | ||||||||||||||||||||||||||||||||||||||||||||||
| (userlogoutPreviousSession: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (userlogoutPreviousSession.statusCode === 200) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.authService | ||||||||||||||||||||||||||||||||||||||||||||||
| .login( | ||||||||||||||||||||||||||||||||||||||||||||||
| this.loginForm.controls.userName.value, | ||||||||||||||||||||||||||||||||||||||||||||||
| encryptPassword, | ||||||||||||||||||||||||||||||||||||||||||||||
| true, | ||||||||||||||||||||||||||||||||||||||||||||||
| this.enableCaptcha | ||||||||||||||||||||||||||||||||||||||||||||||
| ? this.captchaToken | ||||||||||||||||||||||||||||||||||||||||||||||
| : undefined, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .subscribe( | ||||||||||||||||||||||||||||||||||||||||||||||
| (userLoggedIn: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 223 in src/app/user-login/login/login.component.ts
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (userLoggedIn.statusCode === 200) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (userLoggedIn?.data?.previlegeObj[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.sessionstorage.setItem( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'loginDataResponse', | ||||||||||||||||||||||||||||||||||||||||||||||
| JSON.stringify(userLoggedIn.data), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.trackingService.setUserId( | ||||||||||||||||||||||||||||||||||||||||||||||
| userLoggedIn.data.userID, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.authService.sessionExpiredHandled = | ||||||||||||||||||||||||||||||||||||||||||||||
| false; | ||||||||||||||||||||||||||||||||||||||||||||||
| this.sessionstorage.setItem( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'loginDataResponse', | ||||||||||||||||||||||||||||||||||||||||||||||
| JSON.stringify(userLoggedIn.data), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+226
to
+238
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate session storage write.
🧹 Proposed fix if (userLoggedIn?.data?.previlegeObj[0]) {
- this.sessionstorage.setItem(
- 'loginDataResponse',
- JSON.stringify(userLoggedIn.data),
- );
this.trackingService.setUserId(
userLoggedIn.data.userID,
);
this.authService.sessionExpiredHandled =
false;
this.sessionstorage.setItem(
'loginDataResponse',
JSON.stringify(userLoggedIn.data),
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| this.getServicesAuthdetails( | ||||||||||||||||||||||||||||||||||||||||||||||
| userLoggedIn.data, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'Seems you are logged in from somewhere else, Logout from there & try back in.', | ||||||||||||||||||||||||||||||||||||||||||||||
| 'error', | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(userLoggedIn); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 254 in src/app/user-login/login/login.component.ts
|
||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(error); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(userlogoutPreviousSession); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(error); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| sessionStorage.clear(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.router.navigate(['/login']); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert(res.errorMessage, 'error'); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(res); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert(res.errorMessage, 'error'); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(res); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| (err) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert(err, 'error'); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.showLoginError(err); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private showLoginError(error: any) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.resetCaptcha(); | ||||||||||||||||||||||||||||||||||||||||||||||
| this.confirmationService.alert(this.getLoginErrorMessage(error), 'error'); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private getLoginErrorMessage(error: any): string { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof error === 'string' && error.trim()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return error; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (error?.errorMessage && typeof error.errorMessage === 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||
| return error.errorMessage; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (error?.message && typeof error.message === 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||
| return error.message; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||
| error?.error?.errorMessage && | ||||||||||||||||||||||||||||||||||||||||||||||
| typeof error.error.errorMessage === 'string' | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return error.error.errorMessage; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (error?.error?.message && typeof error.error.message === 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||
| return error.error.message; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return 'Unable to login. Please try again.'; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| getServicesAuthdetails(loginDataResponse: any) { | ||||||||||||||||||||||||||||||||||||||||||||||
| const userName: any = this.loginForm.controls.userName.value; | ||||||||||||||||||||||||||||||||||||||||||||||
| sessionStorage.setItem('key', loginDataResponse.key); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 38
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 175
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 50368
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 117
🏁 Script executed:
# Read set-password.component.ts, focusing on lines 138-141 wc -l src/app/user-login/set-password/set-password.component.tsRepository: PSMRI/HWC-UI
Length of output: 117
🏁 Script executed:
# Read http-interceptor.service.ts around lines 112-114 wc -l src/app/app-modules/core/services/http-interceptor.service.tsRepository: PSMRI/HWC-UI
Length of output: 121
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 742
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 822
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1764
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1476
🏁 Script executed:
# Let's see the full context of set-password.component.ts to understand the flow cat -n src/app/user-login/set-password/set-password.component.tsRepository: PSMRI/HWC-UI
Length of output: 6105
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 38
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 504
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 588
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1342
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 719
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1049
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 105
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 343
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 654
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 38
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 3728
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1106
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 38
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1664
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 1242
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 38
🏁 Script executed:
Repository: PSMRI/HWC-UI
Length of output: 553
Add defensive error extraction in set-password.component's error handler.
The error handler at line 140 directly accesses
error.errorMessage, but the interceptor returnserror.error || errorwithout guaranteeingerrorMessageexists. Iferror.erroris falsy, the rawHttpErrorResponseis thrown (which lackserrorMessage). Use defensive extraction likelogin.component.ts(lines 295-315) to safely handle missing or nested error messages:Example pattern:
🤖 Prompt for AI Agents