This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 9882e3bb authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Resolving problems with required login

parent 6a3798ce
No related merge requests found
<div >
<div *ngFor="let watchList of myWatchLists">{{watchList.name}}
<div *ngFor="let watchList of getMyWatchLists()">{{watchList.name}}
</div>
</div>
......
......@@ -2,6 +2,9 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { UserWatchListService } from '../entities/user-watch-list/user-watch-list.service';
import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
import { AccountService } from 'app/core/auth/account.service';
import { Subscription } from 'rxjs';
import { Account } from 'app/core/user/account.model';
@Component({
......@@ -11,16 +14,21 @@ import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
})
export class WatchlistComponent implements OnInit, OnDestroy {
account: Account | null = null;
authSubscription?: Subscription;
myWatchLists: IUserWatchList[] | undefined;
constructor(
protected watchListService: UserWatchListService,
private accountService: AccountService,
) {
}
ngOnInit(): void {
if (!this.myWatchLists) {
getMyWatchLists(): IUserWatchList[] {
if(!this.isAuthenticated()) return [];
if (!this.myWatchLists) {
this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => {
if (data.body) {
this.myWatchLists = data.body;
......@@ -33,11 +41,24 @@ export class WatchlistComponent implements OnInit, OnDestroy {
}
})
return[];
} else {
return this.myWatchLists;
}
}
ngOnDestroy(): void {
ngOnInit(): void {
this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => (this.account = account));
}
isAuthenticated(): boolean {
return this.accountService.isAuthenticated();
}
ngOnDestroy(): void {
if (this.authSubscription) {
this.authSubscription.unsubscribe();
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment