Reputation: 2061
Im using Appsync in a Vue application and have Cognito user pools setup for users to be able to sign-in to my application. However, there are some pages on my app where a non-signed in user should be able to view only ie: "think: reading answers on stack overflow" , however there are some cases where users need to be able to add a comment to that page and need to sign in to edit it.
On my API in Appsync I have the authorization set to "Amazon Cognito User Pool" and the default action set to "Allow" but then how can I make it so non-cognito users can still view a page? What combination of settings should I use?
Upvotes: 2
Views: 988
Reputation: 8482
Annoyingly AppSync does not support multiple authentication methods, and as you've noticed Cognito UserPool integration requires users to have signed in before they can access the graphql endpoint.
There are a few workarounds, however none of them are that pretty:
viewer
. This might be the access token that Cognito returns on authentication. Each resolver would then be responsible for determining if the token is valid (e.g.cognito::getUser
) or access is allowed without a viewer
defined.Although it initially sounds like the hardest, I would recommend my first solution. There are ways of automating AppSync deployments, and it makes a clear distiniction between what's open and what's secured on your schema.
Upvotes: 2