Update is a library for seamless billing and entitlement management. It integrates with your existing tools, like Stripe and Supabase, so you can integrate without migrating away from your existing stack.
The easiest way to get started with Update is to use the create-update-app
command:
npm create update@latest
This tool will help you choose a framework and set up a fully working Update application in seconds. Just provide a name and your API keys.
For source code examples, check out our examples repository.
- Billing: Seamless payments management
- Entitlements: Simple access control for premium features
- Framework Support: Built-in integration for Next.js and other SSR environments
npm install @updatedev/js
First, you need to create an account on Update and obtain your publishable key. This key is essential for initializing the Update client in your application. Additionally, configure your preferred authentication provider to manage user sessions and access control.
import { createClient } from '@updatedev/js';
export async function createUpdateClient() {
return createClient(process.env.NEXT_PUBLIC_UPDATE_PUBLISHABLE_KEY!, {
getSessionToken: async () => {
// This must be replaced with your own logic to get your session token
// For example, with Supabase:
//
// import { createSupabaseClient } from '@/utils/supabase/client'
// ...
// const supabase = createSupabaseClient()
// const { data } = await supabase.auth.getSession()
// if (data.session == null) return
// return data.session.access_token
// For this example, we'll just return a static token
return 'your-session-token';
},
environment: process.env.NODE_ENV === 'production' ? 'live' : 'test',
});
}
getSessionToken
: A function that returns a session token for the user. This is optional, but required for most functions that require authentication.environment
: The environment to use for the client. Valid values arelive
andtest
.
NEXT_PUBLIC_UPDATE_PUBLISHABLE_KEY=
Update works well with Next.js and other SSR environments. Create a utils/update
directory with these files:
import { createClient } from '@updatedev/js';
export async function createUpdateClient() {
return createClient(process.env.NEXT_PUBLIC_UPDATE_PUBLISHABLE_KEY!, {
getSessionToken: async () => {
// This must be replaced with your own logic to get your session token
// For example, with Supabase:
//
// import { createSupabaseClient } from '@/utils/supabase/client'
// ...
// const supabase = createSupabaseClient()
// const { data } = await supabase.auth.getSession()
// if (data.session == null) return
// return data.session.access_token
// For this example, we'll just return a static token
return 'your-session-token';
},
environment: process.env.NODE_ENV === 'production' ? 'live' : 'test',
});
}
import { createClient } from '@updatedev/js';
export async function createUpdateClient() {
return createClient(process.env.NEXT_PUBLIC_UPDATE_PUBLISHABLE_KEY!, {
getSessionToken: async () => {
// This must be replaced with your own logic to get your session token
// For example, with Supabase:
//
// import { createSupabaseClient } from '@/utils/supabase/server'
// const supabase = await createSupabaseClient()
// const { data } = await supabase.auth.getSession()
// if (data.session == null) return
// return data.session.access_token
// For this example, we'll just return a static token
return 'your-session-token';
},
environment: process.env.NODE_ENV === 'production' ? 'live' : 'test',
});
}
const { data, error } = await client.billing.getProducts();
const { data, error } = await client.billing.createCheckoutSession(priceId, {
redirect_url: 'http://localhost:3000/subscription',
});
Get user subscriptions:
const { data } = await client.billing.getSubscriptions();
Cancel a subscription:
await client.billing.updateSubscription(id, {
cancel_at_period_end: true,
});
Reactivate a subscription:
await client.billing.updateSubscription(id, {
cancel_at_period_end: false,
});
const { data, error } = await client.entitlements.list();
const { data, error } = await client.entitlements.check('premium');
For complete documentation, visit our documentation.
Need help? Join our Discord community for support and discussions.
MIT