原型导出 - TypeError: x is not a function

时间:2021-04-08 14:37:19

标签: javascript node.js

服务/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

为什么?

0 个答案:

没有答案