UNPKG

@shopify/shopify-app-express

Version:

Shopify Express Middleware - to simplify the building of Shopify Apps with Express

26 lines (23 loc) 595 B
import {HttpResponseError, Session, Shopify} from '@shopify/shopify-api'; const TEST_GRAPHQL_QUERY = `query shopifyAppShopName { shop { name } }`; export async function hasValidAccessToken( api: Shopify, session: Session, ): Promise<boolean> { 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; } } }