JavaScript SDK
The JavaScript SDK provides browser authentication, React UI and Node.js integrations. The examples and generated reference use the committed source recorded in the source manifest.
To keep tokens on your application backend, use the optional BFF server-session integration. The existing examples below retain their browser-token/Bearer behavior.
Install from source
Build matching core and framework packages from the same commit. This guide uses Node.js 24 and pnpm 11.9.0. The packages are not currently published to npm; use these local build artifacts in your application.
git clone https://github.com/axis-iam/vertex-sdk-js.git
cd vertex-sdk-js
git checkout 21bccfc0079474aa655efbaddc1331b30c83e928
pnpm install --frozen-lockfile
pnpm --filter @axis-iam/vertex-react... build
mkdir -p artifacts
pnpm --dir packages/core pack --out ../../artifacts/vertex-core.tgz
pnpm --dir packages/react pack --out ../../artifacts/vertex-react.tgz
From your application directory, install both artifacts (adjust the relative path to the cloned repository):
npm install ../vertex-sdk-js/artifacts/vertex-core.tgz ../vertex-sdk-js/artifacts/vertex-react.tgz
For Express, build and pack packages/express with core in the same way. NestJS additionally depends on the matching
Express package; install core, Express and Nest artifacts together. See BFF package wiring.
Framework packages do not replace core.
React SPA quickstart
import {IamProvider, SignIn, useAuth} from '@axis-iam/vertex-react';
function Session() {
const {isAuthenticated, user, logout} = useAuth();
if (!isAuthenticated) return <SignIn />;
return <button onClick={() => void logout({redirect: true})}>Sign out {user?.name}</button>;
}
export function App() {
return (
<IamProvider
issuerUri="https://auth.example.com"
clientId="your-spa-public-client-id"
redirectUri="https://app.example.com/callback"
postLogoutRedirectUri="https://app.example.com/signed-out"
>
<Session />
</IamProvider>
);
}
The provider uses Authorization Code + S256 PKCE and keeps tokens in memory by default. Browser code never receives a
client secret. Use @axis-iam/vertex/server, Express or NestJS only in server runtimes with a
WEB/M2M confidential client.
Browser configuration
| Provider value | Portal source | Rule |
|---|---|---|
issuerUri | Vertex public Auth URL | HTTPS base URL, with no API path |
clientId | Clients -> SPA client ID | Public ApplicationClient.clientId, never the Application UUID |
redirectUri | SPA redirect URI | Exact allowlisted callback |
postLogoutRedirectUri | SPA post-logout URI | Exact allowlisted URI |
audience | Application resource audience | API identifier, not a client ID |
tokenStorage | Application decision | Memory by default; opt in to sessionStorage only after accepting its XSS risk |
Hosted redirect and callback
Hosted is the default browser mode. It sends the user to the Vertex-hosted page and returns through the SPA callback.
import {SignIn} from '@axis-iam/vertex-react';
export function LoginPage() {
return <SignIn mode="redirect" />;
}
On the registered callback route, call useAuth().handleRedirectCallback({cleanUrl: '/callback'}) once for the
current callback, consume any promise rejection, and handle every result:
status | Application behavior |
|---|---|
success | OAuth exchange and authenticated views completed; continue into the application |
session | A configured server-session flow completed; continue into the application |
continuation | Preserve the returned transaction and view; render the required MFA step |
error | Show the returned error and a deliberate sign-in retry |
idle | No consumable callback is present; offer the sign-in entry instead of an indefinite spinner |
For continuation, no session has been issued. Render the offered MFA proof and use
transaction.verifyMfa('TOTP', code) or the offered recovery-code method, then
client.completeAuthentication(transaction) through useAuth().client when the returned view permits completion.
The lower-level transaction method takes method, code; the useAuthFlow action takes code, method.
The Custom form flow automatically restores its own Provider return through useAuthFlow. Do not have the Hosted callback handler consume that same return.
The React package guide
describes Provider return, MFA and callback ownership.
An invitation popup uses a passive callback consumed by its opener, rather than this standalone callback handler.
Embedded
Embedded keeps password and passwordless UI inside the application. The SDK discovers enabled and runtime-ready methods in the Application identified by the SPA client. Policy stays Application-owned. Credential proof and required MFA share a controlled transaction, followed by OAuth code exchange with S256 PKCE; refresh also uses OAuth.
<SignIn mode="embedded" onSuccess={() => window.location.assign('/')} />
Email OTP signs in an existing active Application user. Signup is a separate SignUp mode="embedded" flow and must
follow the Application signup mode, email-verification policy, and optional registration-grant contract.
Prebuilt Dialog
Dialog is a controlled presentation of the same Hosted or Embedded engines, not a third authentication protocol.
import {useState} from 'react';
import {AuthDialog, SignInButton} from '@axis-iam/vertex-react';
export function AuthEntry() {
const [open, setOpen] = useState(false);
return (
<AuthDialog open={open} onOpenChange={setOpen} mode="embedded" allowSignUp>
<SignInButton>Sign in</SignInButton>
</AuthDialog>
);
}
Use mode="redirect" when the dialog should open the Hosted flow. In redirect mode, login and ordinary open signup
share one hosted entry; do not add decorative tabs that lead to the same route.
Custom, account security and invitations
- Custom authentication uses public
useAuthFlowstate/actions with host-owned markup. - Account security covers AccountCenter's six sections, MFA and identity operations.
- Invitations covers Application/Organization acceptance, registration and explicit confirmation. Workspace developer invitations remain a separate control-plane workflow.
Node.js resource server
Node APIs use a different WEB/M2M confidential client under the same Application. The browser sends its bearer access token to the API; Express verifies the token and resolves current permissions through Vertex.
import express from 'express';
import {permKey} from '@axis-iam/vertex';
import {iamAuth, requirePerm} from '@axis-iam/vertex-express';
const app = express();
app.use(iamAuth({
endpoint: process.env.IAM_ENDPOINT!,
clientId: process.env.IAM_CLIENT_ID!,
clientSecret: process.env.IAM_CLIENT_SECRET!,
resourceAudience: process.env.IAM_RESOURCE_AUDIENCE!,
}));
app.get('/orders', requirePerm(permKey('orders', 'read')), (_request, response) => {
response.json({orders: []});
});
IAM_CLIENT_ID and IAM_CLIENT_SECRET here belong to the server client, not the SPA. Use a separate exact-scope M2M
client for Portal Open API management; never call management APIs from browser code.
Reference
The generated reference uses the same source manifest as this guide and covers core, React, Express, NestJS, codegen and testing: