> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.credit.aarthiklabs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.credit.aarthiklabs.com/_mcp/server.

# Exit Button

> Handle the Hosted Exit action after a Hybrid borrower is handed off to Hosted Experience.

In Hybrid Experience, your product owns the borrower journey until offer selection. After the borrower selects an offer, your back-end requests a Hosted URL and opens Hosted Experience for selected-offer execution.

The Hosted surface can show an `Exit` button after this handoff. This gives the borrower a clear way to leave the Aarthik Labs hosted step and return to your product.

## Where It Applies

The Exit button applies after Hybrid has moved the borrower into Hosted Experience:

```txt
GET /api/v1/hybrid/personal-loan/borrowers/{borrowerProviderID}/journey/offers/{offerID}/hosted
```

The returned `hosted_url` is short-lived and should be opened immediately in the borrower browser, webview, or app shell.

For Hybrid handoff URLs, the Hosted session is created with the exit action enabled. Your app should be ready to handle the exit event before opening the returned `hosted_url`.

## Handoff Flow

```mermaid
flowchart TD
  A["Borrower selects an offer in your Hybrid UI"] --> B["Your back-end requests hosted_url"]
  B --> C["Your front-end opens Hosted Experience"]
  C --> D["Borrower taps Exit"]
  D --> E["Hosted sends aarthik-labs:exit"]
  E --> F["Your app closes Hosted or returns to your own screen"]
```

## What The Borrower Sees

When the borrower is inside the Hosted handoff surface, Hosted shows an `Exit` button in the header.

When the borrower selects it, Hosted:

1. clears the borrower session from the Hosted browser surface
2. clears the applied Hosted theme from the page
3. sends an `aarthik-labs:exit` event to the parent web page or mobile bridge
4. attempts a best-effort browser close for Hybrid-to-Hosted sessions

The browser close is best-effort because browsers only allow `window.close()` in some contexts. Your app should still handle the exit event and close or hide the Hosted surface itself.

## Web Handling

If your Hybrid UI opens Hosted in an `iframe`, modal, popup, or app-controlled browser surface, listen for the exit event.

```ts
const handleAarthikLabsMessage = (event: MessageEvent) => {
  if (event.data?.type !== "aarthik-labs:exit") return;

  // Close the Hosted handoff surface and return to your Hybrid UI.
  closeHostedExperience();
  showHybridHomeOrDashboard();
};

window.addEventListener("message", handleAarthikLabsMessage);
```

The event payload looks like this:

```json
{
  "type": "aarthik-labs:exit",
  "version": 1,
  "payload": {
    "tenantID": "tenant-123",
    "applicationID": "application-123",
    "borrowerProviderID": "borrower-provider-123",
    "timestamp": "2026-05-01T08:00:00.000Z"
  }
}
```

Use the event to close the Hosted surface. Do not use it as a loan-status signal. Loan progress should still come from the Hybrid APIs and lifecycle web-hooks.

## Mobile App Handling

If your Hybrid journey runs inside a mobile app, register the mobile bridge before opening the Hosted URL.

Hosted can send the exit event through the supported mobile bridge surfaces, including:

* `ReactNativeWebView.postMessage`
* `webkit.messageHandlers.AarthikLabs.postMessage`
* `flutter_inappwebview.callHandler("onAarthikLabsExit", ...)`
* `AarthikLabs.postMessage`

When your app receives `aarthik-labs:exit`, close the Hosted webview or route the borrower back to your Hybrid app screen.

Read [Mobile App Bridge](/documentation/common/mobile-applications/bridge) for the full bridge contract.

## Recommended Behavior

For Hybrid integrations, we recommend:

* register the web or mobile message handler before opening `hosted_url`
* close or hide the Hosted surface after receiving `aarthik-labs:exit`
* return the borrower to your product home, loan dashboard, or offer-summary screen
* continue using lifecycle web-hooks and Hybrid APIs for actual journey status
* request a fresh `hosted_url` if the borrower chooses to continue the selected offer later

Do not reuse an old `hosted_url` as a resume link. It contains short-lived session material and may expire.

## Testing Checklist

Before launch, test:

* the Hybrid offer-selection flow returns a `hosted_url`
* the Hosted URL opens immediately after offer selection
* the `Exit` button is visible after handoff
* clicking Exit sends `aarthik-labs:exit`
* your web page, webview, or app shell closes or hides Hosted
* the borrower lands on the intended Hybrid app screen
* reopening the selected offer requests a fresh `hosted_url`
* mobile bridge handling works on real Android and iOS devices, if applicable