How to make authorized "post" request strapi graphql apollo nextjs

Viewed 162

I am building an ecommerce website using strapi, apollo, graphql, nextjs, when an authenticated users ordering they need to send jwt token using headers but I am little confused how to do that. Here is my code on apollographql playground.

mutation Mutation($data: OrderInput!) {

createOrder(data: $data) { data { id attributes { name phone products { data { id attributes { price name media { data { attributes { url } } } } } } status details createdAt user { data { attributes { username } } } } } } }enter image description here enter image description here

When I do that it is giving following error.

{

"errors": [ { "message": "Forbidden access", "extensions": { "error": { "name": "ForbiddenError", "message": "Forbidden access", "details": {} }, "code": "FORBIDDEN" } }, { "message": "Forbidden access", "extensions": { "error": { "name": "ForbiddenError", "message": "Forbidden access", "details": {} }, "code": "FORBIDDEN" } } ],

Without authorisation its working fine, but I do not know how to insert jwt token

its my order content type, has relation with user

2 Answers

Looks fine to me. You probably inserted an expired token. Have you tried turning on the create permission for authenticated role?

Finally I solved the issue by allowing "find" method in user permission tab.enter image description here

Related