0

I'm very new to AWS. I am trying to use Serverless and Cognito signup a new user. I am using Apollo/GraphQL (and I am seeing all the info I want from the front end) but I have everything hardcoded to eliminate any request errors. For the life of me, I can't figure out why I can't get a new user to register:


const { ApolloServer, gql } = require('apollo-server-lambda');
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
global.fetch = require('node-fetch');

const USER_POOL_ID = 'us-east-1_XXXXXXXXX';
const USER_POOL_APP_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXXX';

const POOL_PARAMS = {
  UserPoolId: USER_POOL_ID,
  ClientId: USER_POOL_APP_ID
}

const UserPool = new AmazonCognitoIdentity.CognitoUserPool(POOL_PARAMS);


const typeDefs = gql`
  type UserSignup {
    email: String!
    name: String!
    password: String!
  }

  type Mutation {
    signup(email: String!, name: String!, password: String!): UserSignup
  }
`;

const resolvers = {
  Mutation: {
    signup: (parentVal, { email, name, password }) => {

      console.log('I can alway see this log');

      const attributeList = [];
      const attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute({ Name: 'email', Value: 'email@email.com' });
      const attributeName = new AmazonCognitoIdentity.CognitoUserAttribute({ Name: 'name', Value: 'mike' });
      attributeList.push(attributeEmail);
      attributeList.push(attributeName);

      console.log('I can see these too ', attributeList);
      console.log('This will return a function ', UserPool.signUp);

      UserPool.signUp('email@email.com', 'P@ssw0rd!', attributeList, null, function(poolErr, poolResult) {
        console.log('I never see a console.log from in here');
        if (poolErr) {
          console.log('ERROR: ', poolErr);
        }
        console.log('RESULT: ', poolResult);
        return { email, name };
      })
    }
  }
};

const server = new ApolloServer({ typeDefs, resolvers });

exports.graphql = server.createHandler();

When I run my sls logs I never see anything return inside of my UserPool.signUp function. It always on the line just before. Here is a look at my serverless.yml file that I got from this SO post.

service: AppName

provider:
  name: aws
  runtime: nodejs8.10

functions:
  graphql:
    handler: handler.graphql
    events:
      - http:
          path: graphql
          method: post
          cors: true
          integration: lambda
          authorizer:
            name: authorizer
            arn: arn:aws:cognito-idp:us-east-1:XXXXXXXXXXXX:userpool/us-east-1_XXXXXXXXX
            claims:
              - email

I was able to create a new user via a curl request so I know I have it setup right on the AWS side. It's been a few nights now and I'm about to scrap Cognito and go with JWTs.

user2465134
  • 8,793
  • 5
  • 32
  • 46
  • 1
    If you are using GraphQL, you should probably consider to use AWS AppSync (AWS GraphQL very powerful and simple solution) with the AWS Amplify framework. Everything you need is in it. https://aws-amplify.github.io/docs/ – Quentin Hayot Jan 22 '19 at 09:02
  • Thanks, I'll give it a look. – user2465134 Jan 22 '19 at 12:59

0 Answers0