REFERENCE
SDK Demos
How to use @asgard-js/core and @asgard-js/react, with demos you can try on the page.
Private
Connect to a private bot provider that requires an API key. The SDK handles
the unauthenticated → needApiKey → authenticated state transitions for
you.
Code Example
import { useState } from "react";
import { Chatbot } from "@asgard-js/react";
import type { AuthState } from "@asgard-js/core";
export function PrivateBot() {
const [authState, setAuthState] = useState<AuthState>("needApiKey");
return (
<Chatbot
title="Private Bot"
config={{
botProviderEndpoint: "https://...",
apiKey: authState === "authenticated" ? storedKey : undefined,
}}
customChannelId="private-channel"
authState={authState}
onApiKeySubmit={async (key) => {
// Validate the key, then switch state
setAuthState("authenticated");
}}
onAuthError={(error) => {
if (error.isAuthError) setAuthState("needApiKey");
}}
/>
);
}Further Reading
For auth design on the platform side, see the Asgard developer docs:
- Authentication
- Workflow Auth pattern