Skip to content

Latest commit

 

History

History
59 lines (36 loc) · 2.01 KB

File metadata and controls

59 lines (36 loc) · 2.01 KB

shopify.session.getCurrentId

Extracts the Shopify session id from the given request.

For embedded apps, shopify.session.getCurrentId will only be able to find a session id if you use authenticatedFetch from the @shopify/app-bridge-utils client-side package. This function behaves like a normal fetch call, but ensures the appropriate headers are set.

Learn more about making authenticated requests using App Bridge.

Example

app.get('/fetch-some-data', async (req, res) => {
  const sessionId = await shopify.session.getCurrentId({
    isOnline: true,
    rawRequest: req,
    rawResponse: res,
  });

  // use sessionId to retrieve session from app's session storage
  // getSessionFromStorage() must be provided by application
  const session = await getSessionFromStorage(sessionId);

  // Build a client and make requests with session.accessToken
  // See the REST, GraphQL, or Storefront API documentation for more information
});

Note: this method will rely on cookies for non-embedded apps, and the Authorization HTTP header for embedded apps using App Bridge session tokens, making all apps safe to use in modern browsers that block 3rd party cookies.

Parameters

Receives an object containing:

isOnline

boolean | ❗ required

Whether to look for an offline or online session, depending on how the auth.begin method was called.

rawRequest

AdapterRequest | ❗ required

The HTTP Request object used by your runtime.

rawResponse

AdapterResponse | ❗ required for Node.js

The HTTP Response object used by your runtime. Required for Node.js.

Return

Promise<string | undefined>

The session id for the request, or undefined if none was found.

Back to shopify.session