Function: withOcAuth()
function withOcAuth<Req, Res>(handler: (req: WithOcSession<Req>, res: Res) => unknown, options?: WithOcAuthOptions): (req: Req, res: Res) => Promise<unknown>;
Defined in: me-client/src/server.ts:735 (opens in a new tab)
Wrap a Next.js Pages-Router API route handler. Adds req.ocSession —
the verified SessionPayload, or null when unauthenticated.
// pages/api/me/profile.ts import { withOcAuth } from '@orangecheck/me-client/server';
export default withOcAuth(async (req, res) => { if (!req.ocSession) return res.status(401).json({ ok: false }); res.status(200).json({ account: { address: req.ocSession.did_oc } }); }, { required: true, audience: 'https://your-site.example (opens in a new tab)' });
audience is your own origin. The sign-in popup issues each site a token
bound to it; a site on *.ochk.io that reads the family cookie omits it.
Cache-Control: no-store, private and Vary: Cookie, Authorization
are set on every authenticated response — without them a cached 401
leaks anonymous to authenticated callers.
Type ParametersLink to this section
| Type Parameter | Default type |
|---|---|
Req extends NextApiRequestLike | NextApiRequestLike |
Res extends NextApiResponseLike | NextApiResponseLike |
ParametersLink to this section
| Parameter | Type |
|---|---|
handler | (req: WithOcSession<Req>, res: Res) => unknown |
options | WithOcAuthOptions |
ReturnsLink to this section
(req: Req, res: Res) => Promise<unknown>