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.
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.
Receives an object containing:
boolean
| ❗ required
Whether to look for an offline or online session, depending on how the auth.begin
method was called.
AdapterRequest
| ❗ required
The HTTP Request object used by your runtime.
AdapterResponse
| ❗ required for Node.js
The HTTP Response object used by your runtime. Required for Node.js.
Promise<string | undefined>
The session id for the request, or undefined
if none was found.