在Angular 4应用程序中创建AWS CognitoUserPool

时间:2017-11-27 10:27:14

标签: javascript angular amazon-web-services typescript aws-sdk

我需要在角度应用程序中使用AWS身份验证。所以,我添加了库文件:

<script src="assets/vendor/jsbn.js"></script>
<script src="assets/vendor/jsbn2.js"></script>
<script src="assets/vendor/sjcl.js"></script>
<script src="assets/vendor/aws-sdk.min.js"></script>
<script src="assets/vendor/aws-cognito-sdk.min.js"></script>
<script src="assets/vendor/amazon-cognito-identity.min.js"></script>

并在我的打字稿文件中导入了sdk:

import AmazonCognitoIdentity = require('aws-sdk');

现在,我需要创建一个userPool。我试过这个:

 private poolData = {
    UserPoolId: "my-pool-id",
    ClientId: "my-client-id"
};

private userPool = new AmazonCognitoIdentity.CognitoIdentityServiceProvider.CognitoUserPool(this.poolData);

但是我收到了错误

  

TypeError:AmazonCognitoIdentity.CognitoIdentityServiceProvider.CognitoUserPool不是构造函数

我使用typescript做了所有描述here的内容。 有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

这两个都可以吗?

var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
import * as AmazonCognitoIdentity from 'amazon-cognito-identity-js';

来自here


我必须执行的其他步骤

我必须在Angular 6应用中执行此操作:

npm i amazon-cognito-identity-js

我遇到此错误:

global is not defined

I had add to polyfill.ts

(window as any).global = window;

通常人们为此'aws-sdk'这样做:

var AWS = require('aws-sdk')