By using AWS re:Post, you agree to the Terms of Use

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?

asked 9 months ago26 views