Skip to main content
The auth proxy securely creates Swish API tokens on your server using your app secret. The client SDK then uses these tokens to communicate directly with the Swish API. On Shopify themes, token creation is handled automatically by the app proxy. Headless environments - Hydrogen, Next.js, or any custom storefront - need to run their own token endpoint using the @swishapp/auth-proxy package.
If you’re using a Shopify theme, skip this page. Token creation is already handled for you.

Installation

Quick start

Create an auth proxy instance and expose createToken as a server route. The proxy validates the request, creates a token using the Swish API, and returns it to the client.

Configuration

How it works

When createToken(request) is called:
  1. The proxy calls your authenticate callback to identify the customer.
  2. It reads the request body and forwards it to POST /profiles/token on the Swish API, authenticated with your authToken.
  3. If the body contains a customer field, the proxy validates that it matches the authenticated customer ID. A mismatch returns a 401 response. This prevents a client from requesting tokens for other customers.
  4. The upstream response is returned directly to the client.
Any unexpected error is passed to onError and returned to the client as a 401.

Framework examples

Hydrogen

Expose the proxy as a Remix action on a server route.
app/routes/api.swish-token.ts

Next.js

Expose the proxy as a Route Handler.
app/api/swish-token/route.ts

SDK configuration

Configure the SDK to use your auth proxy route by setting auth.tokenUrl to match the server endpoint you created above.
On Shopify themes this defaults to /apps/wishlist/api/profiles/token and does not need to be set.