Skip to main content

Host authentication providers

Adapt your identity provider to the runtime client's official token callback. The provider must issue a JWT accepted by the host's Convex auth configuration; an application session cookie alone does not grant Cortex authority.

import { CortexRuntimeClient } from '@cortexmemory/sdk/runtime';

export function connectIdentity(options: {
deploymentUrl: string;
assetHttpUrl: string;
fetchToken: (request: { forceRefreshToken: boolean }) => Promise<string | null>;
clearPrivateViews: () => void;
}) {
return new CortexRuntimeClient({
deploymentUrl: options.deploymentUrl,
assetHttpUrl: options.assetHttpUrl,
fetchToken: options.fetchToken,
onAuthChange: authenticated => {
if (!authenticated) options.clearPrivateViews();
},
});
}

Translate forceRefreshToken into the provider's refresh operation. Return null after sign-out and close the owned runtime client at view/session end. Do not cache a token indefinitely or put it in NEXT_PUBLIC_* configuration.

Provision current principal/membership/grants through trusted administration. Custom claims can be application metadata but cannot fabricate Cortex tenant or capability access. Accepted issuer/audience/JWKS and current authority must agree.

The first-party token form is a minimal development adapter and keeps the JWT in memory. Existing Auth.js/account modules are separate compatibility examples; their session records do not automatically provision runtime grants.

See auth integration and authentication.