gpt4 book ai didi

javascript - Amazon Cognito 与 Javascript AWSCognito 未定义错误

转载 作者:行者123 更新时间:2023-12-02 14:26:37 25 4
gpt4 key购买 nike

以下是我的 app.js 文件。在浏览器上,当用户单击提交按钮时,将调用方法 app.post('/ttt', function (req,res)。我正在尝试使用 Amazon Cognito 成功注册用户。但是,我收到一条错误消息,指出 AWSCognito is not undefined。我该如何解决此问题?

我正在关注this教程。

var express = require('express');

var AWSCognito = require('/Applications/XAMPP/xamppfiles/htdocs/my/p/js/aws-cognito-sdk.js');

var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());

var urlencodedParser = bodyParser.urlencoded({ extended: false });
var jsonParser = bodyParser.json();

var path = require('path');
app.use(bodyParser.json());

var http = require('http');
var fs = require('fs');
var ejs = require('ejs');
var formidable = require("formidable");
var util = require('util');
var AWS = require('aws-sdk');


app.post('/ttt', function (req,res){

AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: '...' // your identity pool id here
});

AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: '...' // your identity pool id here
});

// Need to provide placeholder keys unless unauthorised user access is enabled for user pool
AWSCognito.config.update({accessKeyId: 'anything', secretAccessKey: ''})

var poolData = {
UserPoolId : 'us-east-1_TcoKGbf7n',
ClientId : '4pe2usejqcdmhi0a25jp4b5sh3'
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

var attributeList = [];

var dataEmail = {
Name : 'email',
Value : 'email@mydomain.com'
};
var dataPhoneNumber = {
Name : 'phone_number',
Value : '+15555555555'
};
var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);

attributeList.push(attributeEmail);
attributeList.push(attributePhoneNumber);

userPool.signUp('username', 'password', attributeList, null, function(err, result){
if (err) {
alert(err);
return;
}
cognitoUser = result.user;
console.log('user name is ' + cognitoUser.getUsername());
});

}

最佳答案

AWS 目前不支持“要求”导入 Cognito javascript SDK。手动导出SDK后可以重试吗

关于javascript - Amazon Cognito 与 Javascript AWSCognito 未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38184986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com