Vue.js 无法捕获amazon cognito中用户处理程序的成功/失败事件

Vue.js 无法捕获amazon cognito中用户处理程序的成功/失败事件,vue.js,vue-component,amazon-cognito,Vue.js,Vue Component,Amazon Cognito,我是VueJS和AmazonCognito的新手,正在尝试使用我的简单VueJS应用程序登录 我正在使用NPM和网页。我已经按照 下面是我的脚本标签 <script> import {CognitoAuth} from amazon-cognito-auth-js/dist/amazon-cognito-auth export default { name: 'App', methods: { initCognitoSDK: function() {

我是VueJS和AmazonCognito的新手,正在尝试使用我的简单VueJS应用程序登录

我正在使用NPM网页。我已经按照

下面是我的脚本标签

<script>
  import {CognitoAuth} from amazon-cognito-auth-js/dist/amazon-cognito-auth

  export default {
    name: 'App',

methods: {
  initCognitoSDK: function() {
    var authData = {
      AppWebDomain: 'XXX.auth.us-west-2.amazoncognito.com',
      TokenScopesArray: ['phone', 'email', 'profile', 'openid'],
      AdvancedSecurityDataCollectionFlag: false,
      ClientId: 'XXXXXXXXXXXXXXXXXXXXXXX',
      RedirectUriSignIn: 'http://localhost:8080/index.html',
      RedirectUriSignOut: 'http://localhost:8080/sign-out.html'
    };

    var auth = new CognitoAuth(authData);
    auth.userhandler = {
      onSuccess: function (result) {
        alert("Sign in success");
        //showSignedIn(result);
        console.log(result);
      },
      onFailure: function (err) {
        alert("Error!" + err);
      }
    };

    return auth;
  }
}  
}
</script>

从amazon cognito auth js/dist/amazon cognito auth导入{CognitoAuth}
导出默认值{
名称:“应用程序”,
方法:{
initCognitoSDK:函数(){
var authData={
AppWebDomain:'XXX.auth.us-west-2.amazoncognito.com',
TokenScopesArray:['phone'、'email'、'profile'、'openid'],
AdvancedSecurityDataCollectionFlag:false,
客户ID:'xxxxxxxxxxxxxxxxxxxx',
重新定向到点火器:'http://localhost:8080/index.html',
重定向urisignout:'http://localhost:8080/sign-out.html'
};
var auth=新的CognitoAuth(authData);
auth.userhandler={
onSuccess:函数(结果){
警报(“登录成功”);
//显示签名(结果);
控制台日志(结果);
},
onFailure:函数(err){
警报(“错误!”+错误);
}
};
返回auth;
}
}  
}
我看不到成功与失败的警觉。
任何帮助都将不胜感激

您可以尝试此代码。。为我工作

import { Component, OnInit } from '@angular/core';
import { CognitoAuth } from 'amazon-cognito-auth-js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';
  auth: any;
  constructor() {
    //
  }

  ngOnInit() {
    this.auth = this.initCognitoSDK();
    this.auth.getSession();
    const curUrl = window.location.href;
    this.auth.parseCognitoWebResponse(curUrl);
  }

  initCognitoSDK() {
    const authData = {
      ClientId: 'xyz', // Your client id here
      AppWebDomain: 'xyz', // Exclude the "https://" part.
      TokenScopesArray: ['openid'], // like ['openid','email','phone']...
      RedirectUriSignIn: 'xyz',
      UserPoolId: 'xyz',
      RedirectUriSignOut: 'xyz',
      IdentityProvider: '', // e.g. 'Facebook',
      AdvancedSecurityDataCollectionFlag: false
    };

    const auth = new CognitoAuth(authData);

    auth.userhandler = {
      onSuccess: (result) => {
        alert('Sign in success');
        this.showSignedIn(result);
      },
      onFailure: (err) => {
        alert('Error!');
      }
    };
    auth.useCodeGrantFlow();

    return auth;
  }

  showSignedIn(session) {
    console.log('Session: ', session);
  }
}