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회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠