Reference
Examples

Examples

Here are some common examples of how to use Optare SDKs.

Authentication (Browser)

import { OptareClient } from '@optare/optareid-js';
 
const client = new OptareClient({
  baseUrl: 'https://id.optare.one',
  clientId: 'your_client_id',
  token: 'user_access_token', // From OAuth flow
});
 
// Get current user
const user = await client.auth.getMe();
console.log(user.email);

Server-Side with API Key

import { OptareClient } from '@optare/optareid-js';
 
const client = new OptareClient({
  baseUrl: 'https://id.optare.one',
  clientId: process.env.OPTARE_CLIENT_ID!,
  clientSecret: process.env.OPTARE_CLIENT_SECRET!,
  token: process.env.OPTARE_API_KEY!,
});
 
// Create a product
const product = await client.products.create({
  name: 'Pro Plan',
  slug: 'pro',
  features: ['sso', 'advanced-analytics'],
});

Creating an Organization

const orgs = await client.org.list();
const newOrg = await client.org.create('My Team');

Checking License/Entitlements

const hasFeature = await client.license.check('advanced-analytics');
if (hasFeature) {
  // Enable premium feature
}