Auth & Sessions
There are three distinct auth contexts: Shopify OAuth (install), embedded merchant sessions, and the admin/operator PIN.
Shopify OAuth (install)
- Install —
GET /api/auth/install?shop=…builds the Shopify install URL with a signedstate, setsshopify_oauth_state+ return-host cookies, redirects to Shopify. - Callback —
/api/auth/callback(and/auth/callback) validates HMAC + state, exchanges the code for an access token, and stores it encrypted inplatform_connections(TOKEN_ENCRYPTION_KEY).upsertStorecreates/updates thestoresrow and sets trial dates on first install.
Embedded merchant access
- Embedded pages render inside Shopify admin via App Bridge. The shell is detected with the
x-tryvio-shell: embeddedheader (set whenhostis present);layout.tsxinjects the App Bridge script andshopify-api-keymeta only then. - Server pages use
requireInstalledMerchantPageAccess()to resolve the authorizedshopDomainfrom the embedded session/cookies. - Shopify-API-backed route handlers use
resolveAuthorizedShopForShopifyRequest(request).
Storefront (public) requests
- Widget endpoints under
/api/storefront/*are public (CORS-enabled) and are scoped byshopDomain+ a server-createdtryon_sessionsrow. Abuse is bounded byenforceAuditWindowLimit(IP fingerprint) and per-shopper rate limits.
Admin / operator
/adminis gated by a PIN session (requireAdminSession,/api/admin/login,ADMIN_AUTH_EMAIL). All/api/admin/*handlers callrequireAdminSession()and return 401 onUnauthorized.
Token encryption
Access tokens are encrypted at rest using TOKEN_ENCRYPTION_KEY. Never log raw tokens.