Quick Start Guide - Optare ID
Welcome to Optare ID! This guide will help you integrate enterprise-grade authentication into your application in minutes.
Prerequisites
- Node.js: v18 or later
- Package Manager: npm, pnpm, or yarn
- Optare Account: Sign up at id.optare.one (opens in a new tab)
1. CLI Installation & Setup
The Optare CLI is the fastest way to get started. It handles project creation, credential management, and configuration.
# Install the CLI globally
npm install -g @optare/optareid-cli
# Verify installation
optare --versionInitialize Your Project
Run the init command in your project root. This will create an OAuth client and generate your .env file.
# You will need your API Key from the Optare Portal (Settings -> API Keys)
export OPTARE_API_KEY="sk_..."
# Run the interactive setup
optare initFollow the prompts to select your project type (B2C or Enterprise). The CLI will automatically append OPTARE_CLIENT_ID and OPTARE_CLIENT_SECRET to your .env file.
2. React Integration
Install the React SDK and required dependencies.
npm install @optare/optareid-react @optare/optareid-jsWrap Your App
Wrap your application root with OptareProvider.
// app/layout.tsx or src/App.tsx
import { OptareProvider } from '@optare/optareid-react';
export default function RootLayout({ children }) {
return (
<OptareProvider
domain="https://id.optare.one"
clientId={process.env.NEXT_PUBLIC_OPTARE_CLIENT_ID}
redirectUri="http://localhost:3000/callback"
>
{children}
</OptareProvider>
);
}Add Sign In Button
Use the pre-built SignInButton component to trigger the authentication flow.
import { SignInButton, useOptare } from '@optare/optareid-react';
export default function HomePage() {
const { user, isAuthenticated } = useOptare();
if (isAuthenticated) {
return <div>Welcome back, {user.email}!</div>;
}
return <SignInButton />;
}3. Backend Integration (Node.js)
Protect your API routes using the JS SDK.
npm install @optare/optareid-jsimport { OptareClient } from '@optare/optareid-js';
const optare = new OptareClient({
baseUrl: 'https://id.optare.one',
clientId: process.env.OPTARE_CLIENT_ID,
clientSecret: process.env.OPTARE_CLIENT_SECRET,
});
// Example Express middleware
async function requireAuth(req, res, next) {
try {
const token = req.headers.authorization?.split(' ')[1];
const user = await optare.auth.verifyToken(token);
req.user = user;
next();
} catch (error) {
res.status(401).json({ error: 'Unauthorized' });
}
}4. Deployment
When deploying to production (e.g., Vercel, AWS):
- Environment Variables: Ensure
OPTARE_CLIENT_IDandOPTARE_CLIENT_SECRETare set in your deployment environment. - Redirect URIs: Update your OAuth Client settings in the Optare Portal (opens in a new tab) to include your production URL (e.g.,
https://myapp.com/callback).