React components and hooks for RightBrain AI
npm install @rightbrain/react-implicitReact components and hooks for setting up implicit OAuth flow and interacting with the RightBrain AI.
``bash`
npm install @rightbrain/react-implicit @rightbrain/sdk
or with yarn
yarn add @rightbrain/react-implicit @rightbrain/sdk
or with pnpm
pnpm add @rightbrain/react-implicit @rightbrain/sdk
This package provides a React context provider that handles the OAuth 2.0 implicit flow and makes the access token available to your application.
`tsx
import { RightBrainProvider, useTask } from "@rightbrain/react-implicit"
function App() {
return (
organizationId="your-org-id"
projectId="your-project-id"
clientId="your-client-id"
authEndpoint="https://auth.rightbrain.ai/oauth2/auth"
>
)
}
`
The provider automatically handles the OAuth 2.0 implicit flow:
1. If no access token is present, it redirects to the auth endpoint
2. After successful authentication, captures the token from the URL hash
3. Stores the token and makes it available through the context
4. Cleans up the URL by removing the hash parameters
Provider component that must wrap your application to use RightBrain hooks.
#### Props
| Prop | Type | Description |
| ---------------- | -------- | ------------------------------- |
| rightbrainUrl | string | Base URL for the RightBrain API |organizationId
| | string | Your organization ID |projectId
| | string | Your project ID |clientId
| | string | OAuth client ID |authEndpoint
| | string | OAuth authorization endpoint |
Hook for executing RightBrain tasks with the authenticated token.
`tsx``
function MyComponent() {
const { data, isLoading } = useTask("task-id", {
// task parameters
})
if (isLoading) return Loading...
return {/ render your data /}
}
This package implements the OAuth 2.0 implicit flow, which is designed for public clients (like browser-based applications). The access token is stored in memory and is not persisted between page reloads.