Developer guide · Next.js App Router
From a Next.js app
to a Wallet pass.
A server-side helper for generating a signed membership pass with AddPass. Bring your existing authentication and member data.
Integration scaffold, not a complete authentication or membership application. Requires a Next.js server runtime; a static-only Next.js export cannot run this helper.
1. Configure your server secret
Create an API key in the developer portal. Add it to .env.local for development and your hosting provider’s server-side environment for deployment.
ADDPASS_API_KEY=your_key_hereKeep secret files out of Git. Do not use a NEXT_PUBLIC_ prefix, paste the key into an AI chat, or call AddPass directly from browser code.
2. Add the generation helper
lib/addpass.ts
import 'server-only';
// Call only after your app authenticates the user and
// authorizes this member record. Never call during rendering.
export async function createMembershipPass(member: {
name: string;
number: string;
}) {
const apiKey = process.env.ADDPASS_API_KEY;
if (!apiKey) throw new Error('Missing ADDPASS_API_KEY');
const response = await fetch(
'https://app.addpass.io/api/v1/generate',
{
method: 'POST',
cache: 'no-store',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
primaryText: member.name,
logoText: 'My membership app',
secondaryLabelLeft: 'Member number',
secondaryTextLeft: member.number,
}),
},
);
if (!response.ok) {
throw new Error(`Pass generation failed (${response.status})`);
}
const result = await response.json();
if (typeof result.passUrl !== 'string') {
throw new Error('No download URL returned');
}
return result.passUrl;
}
The helper creates a pass only when called. It does not need a separate template ID or a customer-supplied Apple signing certificate.
3. Connect it to your protected action
Call the helper from an authenticated Server Action or POST Route Handler after your existing authorization checks:
- Verify the signed-in user with your app’s authentication system.
- Load the member record from your database and verify that this user may issue its pass.
- Validate fields against the API field reference, including the 36-character limit for
primaryText. - Apply a per-user issuance limit, then call
createMembershipPass(member)once for an explicit user action. - Return the URL to that user and show a “Download Wallet pass” link.
Do not expose this helper as an unrestricted endpoint. Authentication and authorization are intentionally app-specific; the helper alone does not provide them.
4. Test the whole handoff
Generate one sandbox pass, download it and open it on an iPhone. Confirm both API success and Wallet installation. Sandbox passes may have visible test markings.
Show loading and failure states. Do not automatically retry generation: another request may consume allowance. Treat the returned download link as temporary; it is not a permanent member URL. For durable delivery, request the binary pass and store it through your own application.
What comes next?
Add branding and barcode fields after the first pass works. Your app implements membership verification; this scaffold does not implement check-in, installed-pass updates or revocation.
Framework references: Next.js server and client boundaries and Route Handler guidance. This helper has not been tested against a live AddPass key or installed on a device.