Search code examples
graphqlhasura

How to access public api in hasura


I'm running a docker container with admin secret. In the below image, you can see the roles under the permissions window. enter image description here

For category table, I set public role for SELECT option and there is no restriction for that role to access any query.

enter image description here

But my problem is I can't access the query using public role, hasura engine ask admin-secret. see the below image. How can I access this API without giving admin credentials? enter image description here


Solution

  • Relevant docs: https://hasura.io/docs/1.0/graphql/manual/auth/authentication/unauthenticated-access.html#unauthenticated-public-access

    If you are using webhook-based authentication, "for unauthenticated access, you can return a 200 status response with your defined unauthenticated role, e.g: { "x-hasura-role": "<anonymous-role>" }."

    If you are using jwt-based authentication, "you can use the env variable HASURA_GRAPHQL_UNAUTHORIZED_ROLE or --unauthorized-role flag to set a role for unauthenticated (non-logged in) users."

    The unauthenticated role can be called anything, in your case it would be "public"