From 521b0a30b62845093aa62df603ee0120c91945aa Mon Sep 17 00:00:00 2001 From: Denys Oblohin Date: Mon, 5 Apr 2021 20:01:30 +0000 Subject: [PATCH] Fixed incorrect await in constructor in readme sample OKTA-383070 <<>> Artifact: okta-angular --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f118ab87..d0974cd4 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,7 @@ The example below shows connecting two buttons to handle **login** and **logout* ```typescript // sample.component.ts +import { Component, OnInit } from '@angular/core'; import { OktaAuthService } from '@okta/okta-angular'; @Component({ @@ -281,21 +282,22 @@ import { OktaAuthService } from '@okta/okta-angular'; export class MyComponent { isAuthenticated: boolean; constructor(public oktaAuth: OktaAuthService) { - // get authentication state for immediate use - await this.isAuthenticated = this.oktaAuth.isAuthenticated(); - // subscribe to authentication state changes this.oktaAuth.$authenticationState.subscribe( (isAuthenticated: boolean) => this.isAuthenticated = isAuthenticated ); } - login() { - this.oktaAuth.signInWithRedirect({ + async ngOnInit() { + // get authentication state for immediate use + this.isAuthenticated = await this.oktaAuth.isAuthenticated(); + } + async login() { + await this.oktaAuth.signInWithRedirect({ originalUri: '/profile' }); } - logout() { - this.oktaAuth.signOut(); + async logout() { + await this.oktaAuth.signOut(); } } ```