getAccessToken.
Prerequisites
- A registered
client_idandredirect_urifrom Passage - contact us if you need access redirect_urimust match your OAuth callback page (for examplehttps://your-domain.com/oauth/coinlist/callback)client_secretavailable only on the server@coinlist-co/reactinstalled (SDK quickstart)
Wrap your app with CoinListProvider
ConfigureclientId, redirectUri, and getAccessToken so the SDK can run OAuth in the browser and read short-lived access tokens from your session API.
If you omit
baseUrl in ClientConfig, the SDK uses its default API base URL. Set baseUrl when you need the SDK to call a different host (for example your own backend proxy).Sign-in UI (recommended)
Use the packaged sign-in card inside any subtree that already hasCoinListProvider. It calls coinlist.startOAuth() when the user clicks Sign in with CoinList.
@coinlist-co/react pulls in the SDK styles needed for this UI.
For auth gating, loading states, and OffersGrid after sign-in, see partner-demo app/page.tsx.
Server: CoinListServer and session storage
Create a small factory that bindscreateCoinListServer to your outgoing response and session store. The example below uses HTTP-only cookies; adjust to your security model.
Read-only session stores (Server Components)
In Next.js Server Components you can read cookies but cannot write them, so a writableSessionStore is unsafe - a refreshed session would be silently discarded after consuming the refresh token, effectively logging the user out. Since v0.5.1, setSession is optional: omit it to opt into read-only mode explicitly.
accessToken()returns the current token. If it’s expired, the SDK surfaces the 401 immediately instead of attempting a refresh (it won’t waste a network round-trip with a token it knows is dead).completeOAuth()andlogout()throwWritableSessionStoreRequiredErrorsynchronously, before any network call. Use a writable store in your Route Handlers for those flows.
completeOAuth, accessToken()-driven refresh, and logout. Use the read-only store inside Server Components for plain reads (for example, pre-fetching offers with CoinListServer.fetchOffers() for SSR).
Callback route
On the URL you registered asredirect_uri, use useCompleteOAuth: it validates the redirect (state / PKCE via coinlist.completeOAuth), POSTs to your complete endpoint, then runs coinlist.init() so getAccessToken sees the new session.
This matches partner-demo app/oauth/coinlist/callback/page.tsx:
Put this file at a path that matches
NEXT_PUBLIC_COINLIST_REDIRECT_URI. Read reason on your home page (for example via useSearchParams) if you want to show OAuth errors — see partner-demo app/page.tsx.Exchange the code on your backend
The server SDK performs the token exchange — you do not call the token URL with rawfetch in application code.
Serve access tokens to the client
The browser SDK callsgetAccessToken whenever it needs a Bearer token. Implement this route with coinlistServer(response).accessToken() so refresh happens server-side.
When
accessToken() refreshes the session, the SDK may set cookies on cookieSink. copyCookiesFromTo applies those to the JSON response so the browser gets the updated session cookie.Log out
Clear the session with the server SDK from a route handler:coinlist.logout() on the client when you need to drop the in-memory token after the server clears the session.
Token management
- Access tokens are short-lived. The SDK attaches them as
Authorization: Beareron API requests. - Refresh tokens are long-lived. Keep them on the server. With the server SDK,
accessToken()refreshes when possible. - Never expose
client_secretor long-lived refresh tokens to the browser bundle.
Lower-level and custom integrations
Use the sections below only if you are not using the defaults above.Custom sign-in control (useCoinList + startOAuth)
Custom sign-in control (useCoinList + startOAuth)
If you build your own button or entry point, call
startOAuth() from useCoinList():Manual callback handling (completeOAuth + fetch)
Manual callback handling (completeOAuth + fetch)
You can call
coinlist.completeOAuth() yourself, then POST code and codeVerifier to /api/coinlist/oauth/complete, await coinlist.init(), and redirect. Prefer useCompleteOAuth when possible - it centralizes failure reasons and avoids duplicate work in React Strict Mode.Imperative client (createCoinListClient)
Imperative client (createCoinListClient)
For non-React browser code, import
createCoinListClient and ClientConfig from @coinlist-co/react and call the same methods (startOAuth, completeOAuth, fetchOffers, …). You still need a backend for token exchange in production.Next step
Fetch offers
List offers for the signed-in user with
OffersGrid or hooks, then open Display offer details for one offer.