Oauth error missing_shopify_permission: read_users

Solved
Highlighted
Tourist
6 1 1

Hi guys,

 

I'm building an app that query the list of customers and save the result in an array.

 

I've found this code on Shopify 

import gql from 'graphql-tag';
import { Query } from 'react-apollo';
import { Card } from '@shopify/polaris';
import ApolloClient from 'apollo-boost';


const GET_CLIENTS = gql`
    query{
        customers(first:10){
        edges{
            node{
            email
            acceptsMarketing
            firstName
            state
            updatedAt
            verifiedEmail
            }
        }
        }
    }
`;

class ResourceListWithClients extends React.Component {
      render() {
        return (
          <Query query={GET_CLIENTS}>
            {({ data, loading, error }) => {
              if (loading) return <div>Loading…</div>;
              if (error) return <div>{error.message}</div>;
              console.log(data);
              return (
                <Card>
                  <p>stuff here</p>
                </Card>
              );
            }}
          </Query>
        );
      }
    }
    
export default ResourceListWithClients;

I think that this is ok.

 

I also change the scopes in the server.js file

require('isomorphic-fetch');
const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth');
const { verifyRequest } = require('@shopify/koa-shopify-auth');
const session = require('koa-session');

dotenv.config();
const { default: graphQLProxy } = require('@shopify/koa-shopify-graphql-proxy');
const { ApiVersion } = require('@shopify/koa-shopify-graphql-proxy');

const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
    const server = new Koa();
    server.use(session(server));
    server.keys = [SHOPIFY_API_SECRET_KEY];
    server.use(
        createShopifyAuth({
            apiKey: SHOPIFY_API_KEY,
            secret: SHOPIFY_API_SECRET_KEY,
            scopes: ['read_products', 'write_products', 'read_orders', 'read_users', 'read_customers'],
            afterAuth(ctx) {
                const { shop, accessToken } = ctx.session;
                ctx.cookies.set('shopOrigin', shop, { httpOnly: false });
                ctx.redirect('/');
            },
        }),
    );
    server.use(graphQLProxy({version: ApiVersion.October19}))
    server.use(verifyRequest());
    server.use(async (ctx) => {
        await handle(ctx.req, ctx.res);
        ctx.respond = false;
        ctx.res.statusCode = 200;
        return
    });
    server.listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`);
    });
});

But when I try to launch the app I get this error. 

 

Someone can tell me where I'm wrong?

0 Likes

Success.

Tourist
6 1 1

I'm done

0 Likes