Skip to content
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

fix auth guard on login page #1114

Merged
merged 1 commit into from
Feb 8, 2024
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
4 changes: 4 additions & 0 deletions ui/src/app/account/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const AuthGuard = (route: ActivatedRouteSnapshot, state: RouterStateSnaps
return false
}
} else {
if (state.url === '/login') {
return true
}

router.navigate(['/login'])
stateStorageService.storeUrl(state.url)
return false
Expand Down
12 changes: 7 additions & 5 deletions ui/src/app/account/password/password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export class PasswordComponent implements OnInit {

ngOnInit() {
this.accountService.getAccountData().subscribe((account) => {
this.account = account
this.username = this.accountService.getUsername()
this.passwordForUsernameString = $localize`:@@password.title.string:Password for ${this.username} (You)`
if (account) {
this.account = account
this.username = this.accountService.getUsername()
this.passwordForUsernameString = $localize`:@@password.title.string:Password for ${this.username} (You)`
}
})
}

Expand All @@ -50,8 +52,8 @@ export class PasswordComponent implements OnInit {
error: () => {
this.success = undefined
this.error = 'ERROR'
}
})
},
})
}
}
}
7 changes: 5 additions & 2 deletions ui/src/app/account/service/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeU

import { IAccount } from '../model/account.model'
import { LanguageService } from 'src/app/shared/service/language.service'
import { Router } from '@angular/router'
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//import { MSMemberService } from 'app/entities/member/member.service';

Expand All @@ -21,6 +22,7 @@ export class AccountService {
//private languageService: JhiLanguageService,
private languageService: LanguageService,
private sessionStorage: SessionStorageService,
private router: Router,
private http: HttpClient // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service //private memberService: MSMemberService
) {}

Expand Down Expand Up @@ -104,6 +106,7 @@ export class AccountService {
clearAccountData() {
this.accountData.next(null)
this.authenticated = false
this.router.navigate(['/login'])
}

hasAnyAuthority(authorities: string[]): boolean {
Expand Down Expand Up @@ -159,10 +162,10 @@ export class AccountService {
let username: string | null = null

if (this.isIdentityResolved()) {
if (this.accountData.value!.firstName) {
if (this.accountData.value?.firstName) {
username = this.accountData.value!.firstName
}
if (this.accountData.value!.lastName) {
if (this.accountData.value?.lastName) {
if (username) {
username = username + ' ' + this.accountData.value!.lastName
} else {
Expand Down
6 changes: 2 additions & 4 deletions ui/src/app/layout/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ export class NavbarComponent implements OnInit {
this.username = undefined
if (this.isLoggedAs()) {
this.accountService.logoutAs().subscribe(() => {
window.location.href = '/'
this.router.navigate(['/'])
})
} else {
this.memberService.setManagedMember(null)
this.loginService.logout()
console.log('logged out now')
this.router.navigate(['/login'])
}
}

Expand All @@ -126,7 +124,7 @@ export class NavbarComponent implements OnInit {
this.memberCallDone = false
this.username = undefined
this.accountService.logoutAs().subscribe((res) => {
window.location.href = '/'
this.router.navigate(['/'])
})
}

Expand Down
Loading