Redirect after login with aws-amplify/ui-angular 2.0

0

Hi. I have a Angular application and I like to use the new Authenticator IU compoment. The sample code only show a text message.

<amplify-authenticator>
  <ng-template
    amplifySlot="authenticated"
    let-user="user"
    let-signOut="signOut"
  >
    <h1>Welcome {{ user.username }}!</h1>
    <button (click)="signOut()">Sign Out</button>
  </ng-template>
</amplify-authenticator>

I need to redirect from the login page to the root site. With the old version of the UI components I used "onAuthUIStateChange", but looks like no longer works on aws-amplify/ui-angular 2.0

  ngOnInit(): void {
    onAuthUIStateChange((authState, authData) => {
      this.user = authData as CognitoUserInterface;
      if (authState === AuthState.SignedIn) {
        console.log("user successfully signed in!");
        console.log("user data: ", authData);
        this.router.navigate(['']);
      } else {
        console.log("Status: ", authState);
      }
    })
  }

What is the correct way to redirect after login on an Angular application with aws-amplify/ui-angular 2.0?

質問済み 2年前123ビュー
回答なし

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ