API & SDKs
Backend SDK

Backend SDK

The @optare/node SDK allows you to verify tokens and protect your API endpoints.

Middleware (Next.js / Remix)

Protect your routes by verifying the session token.

import { authMiddleware } from '@optare/node';
 
// middleware.ts
export default authMiddleware({
  publicRoutes: ['/', '/login', '/api/webhooks']
});
 
export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};

Manual Verification

Verify a token manually in your API handlers.

import { optare } from '@/lib/optare';
 
export async function POST(req: Request) {
  const session = await optare.verifySession(req);
 
  if (!session) {
    return new Response('Unauthorized', { status: 401 });
  }
 
  console.log('User:', session.user.id);
  // ...
}