Skip to main content

Custom authentication

Examples on this page use default oauth_tokens. The same UI supports BFF server sessions; use the connected-application transport so code exchange and tokens stay on the backend.

Use useAuthFlow when your application owns the form layout. The hook manages the same authentication transactions as Embedded and Dialog; your UI renders the available methods and current step. Follow the source installation guide for the matching SDK revision.

Mount the form inside IamProvider, configured with the Application's public SPA client and exact registered callback.

import {useAuthFlow} from '@axis-iam/vertex-react';

export function AuthenticationStatus() {
const {state} = useAuthFlow({
initialIntent: 'sign-in',
onSignInSuccess: () => window.location.assign('/'),
});

if (state.error) return <p role="alert">Authentication could not continue.</p>;
return <p role="status">{state.step}</p>;
}

This illustrates hook initialization, not a complete login form. Use the CustomAuth example for a form that renders identifiers, password/code entry, registration, Provider return and MFA.

Render the current step​

The hook returns {state, actions}. Narrow on state.step before reading step-specific fields:

StepHost UI
loadingLoading state
unavailableVisible failure and explicit retry using actions.retryOptions()
identifierServer-offered EMAIL, USERNAME or PHONE input
methodAvailable password, code or magic-link controls for the selected identifier
mfaRequired authenticator or recovery-code confirmation
sign-upPolicy-permitted registration form
verificationRegistration status and required email verification
successCompleted sign-in

Disable conflicting submissions while state.pending !== null. Render the server's ordered identifierMethods and resolved default; do not infer the identifier kind from the text or invent an enabled method. PHONE input needs an explicit country/region when the number cannot be resolved without it.

Connect form actions​

Call actions from the corresponding user interaction:

// Synchronous selection; handle validation errors in your form.
actions.continueWithIdentifier({kind: 'EMAIL', value: email});
actions.selectMethod('password');

// Await these actions and display their typed rejection or state.error.
await actions.submitPassword(password);
await actions.verifyMfa(authenticatorCode, 'TOTP');
// A separate recovery-code action uses verifyMfa(recoveryCode, 'RECOVERY_CODE').

These calls represent different form stages; do not submit password and MFA together. Render only the proof options offered by the current state. Clear passwords and codes after submission or when leaving their input view. Consume promise rejections; cancellation of an obsolete attempt must not trigger a stale navigation or success callback.

Registration uses actions.signUp({identifier, password, registrationGrant?}). It accepts only the effective allowed EMAIL/USERNAME kinds. Its result is a registration profile/operation, not a signed-in session. Verification and any required registration grant remain separate from ordinary login.

Provider and callback handling​

For a user-initiated popup, call await actions.signInWithProvider(providerId). The SDK opens the window, waits for the exact return, resumes the transaction, and cleans up the window and timers.

For a full-page redirect, call await actions.startProvider(providerId) and navigate to the validated URL. Mount useAuthFlow on the registered callback route: autoProviderCallback defaults to true and consumes only the matching CUSTOM transaction, client, issuer, redirect and state binding. Set it to false only when the host explicitly owns callback consumption through actions.resumeProviderCallback(callbackUrl). Hosted callbacks remain with handleRedirectCallback; never attach both consumers to the same return.

A Provider return may restore required MFA rather than complete sign-in. Keep the original tab binding and use an exact registered callback. Never copy transaction controls, proofs or tokens into application URLs, logs or storage.

Continue after a failed login​

Use state.pending !== null for ordinary busy and keep the form visible. A final failure records state.error, ends that attempt and returns to the normal form. If required profile or permission reads fail after tokens were installed, the SDK clears the local session and attempts remote revocation without blocking another login. Local cleanup does not confirm remote IAM or upstream SSO logout. Display the error beside the form and let the user try again; no separate account-loading or session-retry screen is needed.

Follow server cooldowns and original transaction deadlines instead of automatically repeating failed writes. An uncertain completion receives at most one automatic reconciliation with its original key. A sent OAuth code exchange is never replayed.

Await back, cancel, reset and setIntent. If cancellation cannot be confirmed, show cancellationUnconfirmed and preserve a recovery path. Closing the local UI alone does not prove server cancellation. If an already-sent token exchange has an uncertain result, start a fresh sign-in.

For account changes after login, use Account security rather than the public sign-in flow.