@shopify/shopify-app-express
Version:
Shopify Express Middleware - to simplify the building of Shopify Apps with Express
27 lines (24 loc) • 675 B
JavaScript
import { HttpResponseError } from '@shopify/shopify-api';
const TEST_GRAPHQL_QUERY = `query shopifyAppShopName {
shop {
name
}
}`;
async function hasValidAccessToken(api, session) {
try {
const client = new api.clients.Graphql({ session });
await client.request(TEST_GRAPHQL_QUERY);
return true;
}
catch (error) {
if (error instanceof HttpResponseError && error.response.code === 401) {
// Re-authenticate if we get a 401 response
return false;
}
else {
throw error;
}
}
}
export { hasValidAccessToken };
//# sourceMappingURL=has-valid-access-token.mjs.map