Ggmon
Ggmon

Reputation: 748

AWS AMPLIFY: How to specify auth for custom lambda resolvers

How to specify all Cognito users can access custom lambda resolver

type Query {
   tasks: [Task] @function(name: "lambda1-${env}")  
   getTask(id:ID!): Task @function(name: "lambda1-${env}")  
}

type Task {
  id: ID!
  name: String!
}

I am getting unauthorized when doing

    const taskList = await API.graphql({
      query: tasks,
      authMode: 'AMAZON_COGNITO_USER_POOLS'
    });

Upvotes: 0

Views: 425

Answers (1)

Ggmon
Ggmon

Reputation: 748

Finally got it working.

type Query {
   tasks: [Task] @function(name: "lambda1-${env}") @auth(rules: [{ allow: private, provider: userPools }])
   getTask(id:ID!): Task @function(name: "lambda1-${env}")
}

type Task {
  id: ID! @auth(rules: [{ allow: private, provider: userPools }])
  name: String! @auth(rules: [{ allow: private, provider: userPools }])
}

const taskList = await API.graphql({
  query: tasks,
  authMode: 'AMAZON_COGNITO_USER_POOLS'
});

Upvotes: 2

Related Questions