how to @auth Combining Owner/Groups rules for Multi-Tenant Apps?

0

I am using this schema in aws graphql structure. I have stored the tenant ID in aws cognito user pool custom attributes.

type ClientDetails @model @auth( rules: [ { and: [ { allow: owner, ownerField: "tenant", identityClaim: "custom:tenant" } { or: [ { allow: owner, ownerField: "owner" } { allow: groups, groups: ["Customers"], operations: [read] } { allow: groups groups: ["Admin"] operations: [create, update, read] } ] } ] } ] ) { id: ID! tenant: String! OrganizationName: String! SuperUser: String! }

while running the amplify API gql-compile command throws an error. the error was,

Schema validation failed.

Field "AuthRule.allow" of required type "AuthStrategy!" was not provided.

GraphQL request:852:41 852 | type ClientDetails @model @auth(rules: [{and: [{allow: owner, ownerField: "tenan | ^ | t", identityClaim: "custom:tenant"}, {or: [{allow: owner, ownerField: "owner"},

Field "and" is not defined by type "AuthRule".

GraphQL request:852:42 852 | type ClientDetails @model @auth(rules: [{and: [{allow: owner, ownerField: "tenan | ^ | t", identityClaim: "custom:tenant"}, {or: [{allow: owner, ownerField: "owner"},

how do resolve this? share if have any reference Documents, for creating schemas in graphql structure related multitenant.

1개 답변
0
수락된 답변

Thank you for reaching out to us regarding the above query.

As mentioned in the error message, field "and" which is being used in the @auth rules is not defined by type "AuthRule". Kindly note that, in Amplify when combining multiple authorization rules in your schema, they are "logically OR"-ed. Hence, the correct syntax of your schema would look like below :

type ClientDetails 
@model 
@auth( 
  rules: [ 
    { allow: owner, ownerField: "tenant", identityClaim: "custom:tenant" } 
    { allow: owner, ownerField: "owner" } 
    { allow: groups, groups: ["Customers"], operations: [read] } 
    { allow: groups groups: ["Admin"] operations: [create, update, read] }
  ] ) {
id: ID! 
tenant: String! 
OrganizationName: String! 
SuperUser: String! 
}

Further, you might be aware that, combining Owner/Groups rules for Multi-Tenant Apps is an active Feature Request in Amplify and the internal team is aware of it. However, you may refer to the discussion done in the below GitHub Issue which mentions some of the workarounds used by different Amplify Community users.

Having said that, in case you face further challenges, please feel free to open a support case with AWS using the following link.

AWS
지원 엔지니어
답변함 5달 전
profile picture
전문가
검토됨 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠