I'm creating an application that has public data and admins/editors that can log in to change this public data on occasions.
My front page features a call to
const client = generateClient({ authMode: "identityPool" });
const {data, errors} = await client.models.Product.list();
The product model looks like this
Product: a
.model({
...
})
.secondaryIndexes((index) => [
...
])
.authorization((allow) => [
allow.guest().to(["read"]),
allow.authenticated("identityPool").to(["read"]),
allow.authenticated("userPools").to(["read"]),
allow.group("ADMINS"),
])
Currently Guests can view products using the list command. However as soon as I log in i get an un Unorthorized error
"If you're calling an Amplify-generated API, make sure to set the "authMode" in generateClient({ authMode: '...' }) to the backend authorization rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')"
The documentation recommends not using public api key and instead using guest pattern access
But I can't get the identityPool authMode to work with authenticated users. So, I might need to go back to publicApiKey access pattern for public pages.
If i try:
const client = generateClient({ authMode: "userPool" });
const {data, errors} = await client.models.Product.list();
Authenticated users can see the products but the pulic/guest users get an Unauthenticated error.
I have tried variations on:
allow.authenticated()
allow.authenticated("identityPool")
allow.authenticated("userPools")
Nothing seems to work.