Skip to main content

REFERENCE

SDK Demos

How to use @asgard-js/core and @asgard-js/react, with demos you can try on the page.

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.

  1. 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
  2. Code Example​

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

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

Ready to get started?

Want to see how Asgard fits your team? Talk to us.

Contact us