Initialization
Config parameters
OAuth application ID from the Mio dashboard. Exposed to the browser.
Absolute URL where Mio sends users back after the connection flow. Must match the redirect URL registered in the Mio dashboard.
Backend endpoint that swaps authorization codes for tokens on behalf of the browser.
Methods
connect(): Promise<void>
Redirects the browser into the Mio connection flow hosted on the Mio dashboard. Use it inside a click handler.
handleMioCallback(): Promise<MioOauth2TokenResponse>
Exposed via useMio. Reads the code query parameter, clears it from the URL, forwards it to exchangeTokenUrl, and returns the parsed tokens.
MioOauth2TokenResponse containing accessToken, refreshToken, expiresIn, tokenType, and idToken.exchangeCode(code: string): Promise<MioOauth2TokenResponse>
Low-level helper that powers handleMioCallback. Call it manually if you want to parse the URL yourself.
Authorization code received from Mio after the user approves access.
MioOauth2TokenResponse containing accessToken, refreshToken, expiresIn, tokenType, and idToken.getContext({ query, accessToken }): Promise<string>
Retrieves Mio Context for a given user and query and returns the validated context string.
Natural language query used to shape the returned Mio Context.
Token returned by
handleMioCallback or your backend.getContextSummary({ accessToken }): Promise<string | null>
Fetches the latest stored Mio Context summary for the user. Returns null when no summary exists yet.
Token returned by
handleMioCallback or your backend.Returns
Error handling
Not initialized
Not initialized
Mio.getInstance() throws if you skip Mio.init. Initialize inside a provider or at app bootstrap.Token exchange failed
Token exchange failed
exchangeCode throws when the backend responds with a non-2xx status. Check that exchangeTokenUrl is reachable and that your backend logs show the real auth error.Context request failed
Context request failed
getContext and getContextSummary throw a generic error message when the fetch returns a non-2xx code. Inspect your browser network panel to see if the access token expired (401) or if the payload was invalid (400).