소스 검색

Added logout button

Lukas Angerer 3 년 전
부모
커밋
e86996a93d
2개의 변경된 파일25개의 추가작업 그리고 13개의 파일을 삭제
  1. 21 13
      src/RunnersMeet.Client/src/app/app.component.html
  2. 4 0
      src/RunnersMeet.Client/src/app/app.component.ts

+ 21 - 13
src/RunnersMeet.Client/src/app/app.component.html

@@ -1,15 +1,23 @@
 <h1>{{title}}</h1>
 <router-outlet></router-outlet>
-<button type="button" (click)="login()">Login</button>
-<dl>
-	<dt>isLoading</dt>
-	<dd>{{ authService.isLoading$ | async | json }}</dd>
-	<dt>isAuthenticated</dt>
-	<dd>{{ authService.isAuthenticated$ | async | json }}</dd>
-	<dt>user</dt>
-	<dd>{{ authService.user$ | async | json }}</dd>
-	<dt>User Display Name</dt>
-	<dd>{{ (authService.user$ | async)?.nickname }}</dd>
-	<dt>User ID</dt>
-	<dd>{{ (authService.user$ | async)?.sub }}</dd>
-</dl>
+<ng-container *ngIf="!(authService.isLoading$ | async)">
+	<div *ngIf="authService.isAuthenticated$ | async">
+		<dl>
+			<dt>isLoading</dt>
+			<dd>{{ authService.isLoading$ | async | json }}</dd>
+			<dt>isAuthenticated</dt>
+			<dd>{{ authService.isAuthenticated$ | async | json }}</dd>
+			<dt>user</dt>
+			<dd>{{ authService.user$ | async | json }}</dd>
+			<dt>User Display Name</dt>
+			<dd>{{ (authService.user$ | async)?.nickname }}</dd>
+			<dt>User ID</dt>
+			<dd>{{ (authService.user$ | async)?.sub }}</dd>
+		</dl>
+		<button type="button" (click)="logout()">Logout</button>
+	</div>
+	<div *ngIf="!(authService.isAuthenticated$ | async)">
+		Not authenticated
+		<button type="button" (click)="login()">Login</button>
+	</div>
+</ng-container>

+ 4 - 0
src/RunnersMeet.Client/src/app/app.component.ts

@@ -17,4 +17,8 @@ export class AppComponent {
 	public login(): void {
 		this.authService.loginWithRedirect();
 	}
+
+	public logout(): void {
+		this.authService.logout();
+	}
 }