服务/user.js
var AWS = require('aws-sdk'),
amazonCognitoIdentity = require('amazon-cognito-identity-js');
module.exports = function (cognitoUserPool) {
var ddb = new AWS.DynamoDB();
var UserService = function (cognitoUserPool) {
this.userPool = new amazonCognitoIdentity.CognitoUserPool({
UserPoolId : cognitoUserPool.user_pool_id,
ClientId : cognitoUserPool.client_id // App Client id
});
}
UserService.prototype.login = function(email, password) {
// do stuff
}
return UserService;
}
路由/user.js
var express = require('express'),
UserService = require('../services/user');
module.exports = function(serverCredentials){
const router = express.Router();
const userServiceInstance = new UserService(serverCredentials['cognito-user-pool']);
router.post('/auth', function(req, res) {
var email = req.body.email;
var password = req.body.password;
if (email && password) {
userServiceInstance.login(email, password).then(function(result) {
// do stuff
}, function(err) {
// do stuff
})
}
});
}
结果:
TypeError: userServiceInstance.login is not a function
为什么?