Hi,
I’m building an app that first collects both key and secret and then proceeds to OAuth and receives the code (token, to access Shopify data)
I have two issues that may share a solution; All routes in my applications are protected with session token, so users can’t accesss other users data. But now, I have the callback route without auth middleware because the request from shopify (with the token, hmac, host, etc.) does not come with the proper header or cookie.
Also, I’d need to send the callback function data about the user, so the callback function can store and manage properly the token. But I can’t figure how to pass parameters to the url I send to Shopify.
const saveShopifyConnector = async (req, res) => {
try {
const uO = req.user;
const userId = req.user._id;
const data = req.body;
const saved = await saveShopify(userId, data, res);
console.log('saved', saved);
const shop = data.shop;
const key = data.key;
const secret = data.secret;
const scope = 'read_products';
Shopify.Context.initialize({
API_KEY: key,
API_SECRET_KEY: secret,
SCOPES: scope,
HOST_NAME: '2b31-95-187-292-14.ngrok.io',
IS_EMBEDDED_APP: true
})
req.params.userId = userId;
const authRoute = await Shopify.Auth.beginAuth(req, res, shop, '/route-where.receive-shopify-code', false);
return res.status(201).send({url: authRoute});
} catch (err) {
console.log('the error', err);
};
};
I tried to pass an extra object to the beginAuth method but it does not pass it along. I also tried to add ?param=value, in the callback route but it does not work either.
Any idea?
Thanks!