Sanity Library Reference Docs
    Preparing search index...

    Variable useOAuthAuthorizeConst

    useOAuthAuthorize: () => (...params: []) => Promise = ...

    A React hook that returns a function for starting the OAuth authorization-code + PKCE flow.

    Type declaration

      • (): (...params: []) => Promise
      • Returns (...params: []) => Promise

        A function that starts the OAuth flow by navigating to the authorization URL

    The returned function invokes core's startOAuthAuthorization, which generates the PKCE code_verifier, code_challenge and state, persists the verifier and state to sessionStorage, and navigates the browser to the authorize endpoint. clientId, redirectUri and organizationId are read from the instance's auth.oauth config. The returned promise rejects if the instance has no auth.oauth config.

    Pair with useHandleOAuthCallback on the redirect URI to complete the flow.

    function LoginButton() {
    const authorize = useOAuthAuthorize()
    return <button onClick={() => authorize().catch(console.error)}>Sign in</button>
    }