Skip to content

Commit

Permalink
Merge pull request #1061 from ORCID/clean-up-account-service
Browse files Browse the repository at this point in the history
clean up account and login service
  • Loading branch information
bobcaprice authored Jan 10, 2024
2 parents 6c293b8 + e64bd4d commit 5d2aa5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class LoginComponent implements AfterViewInit, OnDestroy {
filter((account) => !!account),
take(1)
)
.subscribe((account) => {
.subscribe(() => {
this.loginSuccess()
})
} else {
Expand Down
10 changes: 3 additions & 7 deletions ui/src/app/account/service/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class AccountService {
private isFetchingAccountData = false
private stopFetchingAccountData = new Subject()
private authenticated = false
private authenticationState = new BehaviorSubject<any>(null)
private logoutAsResourceUrl = '/services/userservice/api'

constructor(
Expand All @@ -39,13 +38,11 @@ export class AccountService {
this.accountData.next(null)
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//this.memberService.memberData.next(undefined);
this.authenticationState.next(this.accountData)
this.isFetchingAccountData = false
return EMPTY
}),
map((response: HttpResponse<IAccount>) => {
this.isFetchingAccountData = false
this.authenticationState.next(this.accountData)
if (response && response.body) {
this.authenticated = true
const account: IAccount = response.body
Expand Down Expand Up @@ -112,10 +109,9 @@ export class AccountService {
)
}
// TODO: any - this seems to only be used for logging out (only ever receives null as arg)
authenticate(identity: any) {
this.accountData.next(identity)
this.authenticated = identity !== null
this.authenticationState.next(this.accountData)
clearAccountData() {
this.accountData.next(null)
this.authenticated = false;
}

hasAnyAuthority(authorities: string[]): boolean {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/account/service/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export class LoginService {
}

logoutDirectly() {
this.accountService.authenticate(null)
this.accountService.clearAccountData()
}

logout() {
if (this.accountService.isAuthenticated()) {
this.authServerProvider.logout().subscribe(() => this.accountService.authenticate(null))
this.authServerProvider.logout().subscribe(() => this.accountService.clearAccountData())
} else {
this.accountService.authenticate(null)
this.accountService.clearAccountData()
}
}
}

0 comments on commit 5d2aa5e

Please sign in to comment.