Skip to main content

Auth

The SDK exposes an authState prop that renders different UI for each phase of the authentication flow. Use it alongside onApiKeySubmit to validate an API key asynchronously.

Auth State

Loading chatbot...

Supported States​

StateUI Behavior
authenticatedNormal chat interface
needApiKeyPrompt the user to enter an API key
invalidApiKeyError state with retry affordance
loadingSpinner while auth is being determined
errorGeneric error UI
subscriptionExpiredBlocking notice with upgrade CTA
botNotFoundBlocking notice when the bot provider 404s

Code Example​

const [authState, setAuthState] = useState<AuthState>("needApiKey");

<Chatbot
authState={authState}
onApiKeySubmit={async (key) => {
const valid = await validate(key);
setAuthState(valid ? "authenticated" : "invalidApiKey");
}}
{...rest}
/>;