Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/app/app-modules/core/services/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { map } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';
import { of } from 'rxjs';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate {
Expand All @@ -37,7 +38,8 @@ export class AuthGuard implements CanActivate {
res && res.statusCode === 200 && res.data
? true
: this.router.createUrlTree(['/login'])
)
),
catchError(() => of(this.router.createUrlTree(['/login'])))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟑 Minor | ⚑ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
git ls-files | rg '(^|/)src/app/(app-modules/core/services/auth-guard.service.ts|login/login.component.ts|.*login.*)\.ts$|(^|/)src/app/.*guard.*\.ts$' || true

echo "== auth guard outline and relevant contents =="
if [ -f src/app/app-modules/core/services/auth-guard.service.ts ]; then
  ast-grep outline src/app/app-modules/core/services/auth-guard.service.ts --view expanded || true
  wc -l src/app/app-modules/core/services/auth-guard.service.ts
  cat -n src/app/app-modules/core/services/auth-guard.service.ts
fi

echo "== login component references =="
rg -n "validateSessionKey|isAuthenticated|authenticationToken|Subscription|Error|CatchError|catchError|ngOnInit" src/app -g '*.ts' || true

echo "== service validation details =="
rg -n "validateSessionKey|isAuthenticated|authenticationToken|isAuthenticated" src/app/src app Common-UI -g '*.ts' 2>/dev/null || true

Repository: PSMRI/MMU-UI

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== login component =="
wc -l src/app/app-modules/login/login.component.ts
sed -n '1,180p' src/app/app-modules/login/login.component.ts

echo "== login spec relevant lines =="
sed -n '1,180p' src/app/app-modules/login/login.component.spec.ts

echo "== focused auth/session references =="
rg -n "validateSessionKey|isAuthenticated|authenticationToken|catchError|Subscription|error" src/app/app-modules/login -g '*.ts' || true
rg -n "validateSessionKey" src/app -g '*.ts' || true

echo "== auth service files =="
git ls-files src/app | rg '(^|/)auth\.service\.ts$|auth-session|session|Auth' || true
for f in $(git ls-files src/app | rg 'auth\.service\.ts$|auth-session|session|Auth'); do
  echo "--- $f"
  wc -l "$f"
  rg -n "validateSessionKey|isAuthenticated|authenticationToken" "$f" -C 4 || true
done

Repository: PSMRI/MMU-UI

Length of output: 10916


Handle session validation errors on login.

AuthGuard redirects to /login on validation failures while sessionStorage.isAuthenticated remains set. LoginComponent.ngOnInit() then subscribes to validateSessionKey() with no error handler, so the invalid session repeats the failing request and propagates an unhandled RxJS error. Clear the stale isAuthenticated state for failed/expired sessions, or handle the validation error in LoginComponent; do not clear credentials for transient server errors.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/app-modules/core/services/auth-guard.service.ts` at line 42, Update
the AuthGuard session-validation flow around catchError and
LoginComponent.ngOnInit so failed or expired session credentials do not remain
marked as authenticated and trigger repeated validation errors. Handle
validation errors in the login initialization path or clear
sessionStorage.isAuthenticated only for confirmed invalid/expired sessions,
while preserving the flag for transient server failures.

);
}
}
8 changes: 7 additions & 1 deletion src/app/app-modules/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ export class LoginComponent implements OnInit, AfterViewInit {
},
err => {
this.resetCaptcha();
this.confirmationService.alert(err, 'error');
const message = [err?.error?.errorMessage, err?.message].find(
msg => !!msg
);
this.confirmationService.alert(
message || 'Login request failed. Please try again.',
'error'
);
Comment on lines +206 to +212

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repository files around login component:"
git ls-files | grep -E '(^|/)login\.component\.ts$|package\.json$|src/app/app-modules/login' | head -100

echo
echo "Login component excerpt:"
if [ -f src/app/app-modules/login/login.component.ts ]; then
  nl -ba src/app/app-modules/login/login.component.ts | sed -n '1,280p'
else
  echo "login.component.ts not found"
fi

echo
echo "Search for status-specific login message handling:"
rg -n "400|401|403|404|409|500|HttpErrorResponse|errorMessage|confirmationService\.alert|Login request failed" src/app/app-modules/login src || true

Repository: PSMRI/MMU-UI

Length of output: 459


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Login component excerpt (wc + sed):"
wc -l src/app/app-modules/login/login.component.ts
sed -n '1,280p' src/app/app-modules/login/login.component.ts

echo
echo "Search for status-specific login handling:"
rg -n "400|401|403|404|409|500|HttpErrorResponse|errorMessage|confirmationService\.alert|Login request failed|status" src/app/app-modules/login src || true

echo
echo "Package script hints:"
python3 -c "
import json
from pathlib import Path
p=Path('package.json')
if p.exists():
    d=json.loads(p.read_text())
    for k,v in d.get('scripts',{}).items():
        if 'lint' in k or 'test' in k or 'build' in k:
            print(f'{k}: {v}')
"

Repository: PSMRI/MMU-UI

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path('src/app/app-modules/login/login.component.ts')
text = p.read_text()
print(f'file_exists={p.exists()} lines={text.count(chr(10))+1}')
for start,end in [(1,80),(180,230)]:
    print(f'\n--- {start}-{end} ---')
    for i,line in enumerate(text.splitlines(),1):
        if start <= i <= end:
            print(f'{i:4}: {line}')

print('\n--- targeted occurrences in login component ---')
for needle in ['confirmationService.alert', 'Login request failed', 'errorMessage', 'HttpErrorResponse', 'status', '400', '401', '403', '404', '409', '500']:
    matches = []
    for i,line in enumerate(text.splitlines(),1):
        if needle in line:
            matches.append(i)
    print(f'{needle}: {matches[:40]}' if len(matches)<=40 else f'{needle}: {matches[:40]} ... count={len(matches)}')
PY

echo
echo "Login spec status/message snippets:"
python3 - <<'PY'
from pathlib import Path
p = Path('src/app/app-modules/login/login.component.spec.ts')
text = p.read_text()
for needle in ['Login request failed', 'errorMessage', 'HttpErrorResponse', 'status', '400', '401', '403', '404', '409', '500', 'confirmationService.alert']:
    matches = [i for i,line in enumerate(text.splitlines(),1) if needle in line]
    print(f'{needle}: first {matches[:10]} count={len(matches)} total_lines={text.count(chr(10))+1}')
PY

Repository: PSMRI/MMU-UI

Length of output: 6101


Map HttpErrorResponse.status in the login error handler.

The error block at src/app/app-modules/login/login.component.ts:206-212 only reads err?.error?.errorMessage and err?.message. This means HTTP 400/401/403/404/409/500 login failures do not use status-specific product messages unless the API provides them in err.error.errorMessage. Keep any API-provided message first, then select messages by err.status, and use the generic fallback only for unmapped or network errors.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/app-modules/login/login.component.ts` around lines 206 - 212, Update
the login error handler’s message selection around confirmationService.alert to
prioritize err?.error?.errorMessage, then map err.status for HTTP 400, 401, 403,
404, 409, and 500 to the corresponding product messages, preserving err?.message
as appropriate. Use the existing generic fallback only when no API or
status-specific message applies, including unmapped and network errors.

}
);
}
Expand Down
Loading