aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

2 auth modes problem #5200

Closed rudyhadoux closed 4 years ago

rudyhadoux commented 4 years ago

Hi,

It is a schema for a chat user. I want that the list of users is public (without private conversations). Sorry to tell that but I think that multiple auth documentation is bad explained.

I do not understand why this does not work :

schema {
   query: Query
}

type Query {
   listUsers(): [User]
   @aws_api_key
}

type User
@model(subscriptions: { level: public })
@key(name: "userByUsername", fields: ["username"], queryField: "userByUsername")
@aws_cognito_user_pools
@aws_api_key {
  id: ID!
  username: String!
  online: Boolean
  conversations: [Conversation]
  @connection(name: "UserConversations")
  @aws_cognito_user_pools
  createdAt: String
  updatedAt: String
}

This schema is rejected. And how to use that with Angular ?

akshbhu commented 4 years ago

Hi @rudyhadoux

Can you tell what is the error you are getting when you said schema is rejected?

Also can you tell how did you setup your API so that I can reproduce this?

rudyhadoux commented 4 years ago

The schema failed after compilation without explanation. Cognito user pool is the default auth mode.

I have an Api key and a Cognito user pool. And storage for other objects.

I have other Amplify web apps workîng but with only a Cognito user pool.

I do not know if in my Angular web app i must have two appsync clients or if the schéma.graphql configuration is enough.

akshbhu commented 4 years ago

Hi @rudyhadoux

You can change your Type Query to either remove arguments from the listUsers like below:

type Query {
   listUsers: [User]
   @aws_api_key
}

or you can put some arguments in your query:

type Query {
   listUsers(id : ID!): [User]
   @aws_api_key
}

Let me know if this solve for issue.

rudyhadoux commented 4 years ago

The schema.graphql was wrong.

That is the good one.

type User @model(subscriptions: { level: public }) @key(name: "userByUsername", fields: ["username"], queryField: "userByUsername") @auth( rules: [ { allow: public, operations: [read] } { allow: private, operations: [read, create, update, delete] } ] ) { id: ID! username: String! online: Boolean conversations: [Conversation] @connection(name: "UserConversations") @auth(rules: [{ allow: private, operations: [read, create, update, delete] }]) createdAt: String updatedAt: String }

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.