Sanity Library Reference Docs
    Preparing search index...

    Variable TokenRefreshProviderConst

    TokenRefreshProvider: React.FC<PropsWithChildren> = ...

    Authenticates the SDK with the Sanity Dashboard's session when the app runs inside the dashboard.

    The dashboard owns the session there: this provider subscribes to the token the dashboard issues, writes each new value into the SDK's auth store (where SDK hooks read it from), and asks the dashboard for a fresh token when a request fails with a 401. Outside the dashboard it renders children unchanged and the app's normal auth flow applies.

    AuthBoundary mounts this automatically, so most apps never need it directly. Mount it yourself only when your app runs inside the dashboard without AuthBoundary — that is, the app renders its own loading and error UI instead of the SDK's login flow — but still uses SDK hooks such as useQuery, which need the dashboard's token in the auth store to authenticate their requests.

    Mount it once, inside the provider that creates the Sanity instance whose store should receive the token.

    import {ResourceProvider} from '@sanity/sdk-react'
    import {TokenRefreshProvider} from '@sanity/sdk-react/dashboard'

    function EmbeddedApp() {
    return (
    <ResourceProvider fallback={<Loading />}>
    <TokenRefreshProvider>
    <App />
    </TokenRefreshProvider>
    </ResourceProvider>
    )
    }