So I have a page in my Shopify Remix React app using code like the below. My question is how do I add the request headers that Shopify is expecting to authenticate the admin request?
fetch('/api/geocode', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({orders})
}).then(res => res.json()).then(data => {
console.log('geocode data', data)
})
On my api.geocode.js I want to validate that they are authorized:
export async function action({request}) {
const { admin } = await authenticate.admin(request); // does not work
const data = await request.json();
}
2
Answers
You can get token from localstorage if you already login into app
After that yo can easily validate if token has header Auth
But if you want to validate if this token valid you can use jsonwebtoken with your secret key
It will be something like this
To authenticate the request to Shopify’s Admin API, you’ll need to include the appropriate headers, such as the X-Shopify-Access-Token, in your fetch request. These headers will be used on the server side to validate the request. Here’s how you can modify your code to include these headers and authenticate the request on the server side.
Let me know if this helps 😀