# prepareSessionTransfer()

The `prepareSessionTransfer()` function creates a one-time link that signs the native app's user in on a page of your web app. Each call creates a new link.

Use it only when you open the link yourself. For a WebView, use [useAuthenticatedWebView()](https://clerk.com/docs/expo/reference/native-hooks/use-authenticated-web-view.md) instead. For the default browser, use [openInBrowser()](https://clerk.com/docs/expo/reference/open-in-browser.md).

> The link signs in anyone who opens it. Open it once, within 60 seconds, and never log or store it.

For setup steps, see [Open your web app signed in from a native app](https://clerk.com/docs/guides/development/native-to-web.md).

Import the function from the `@clerk/expo/native-to-web` subpath:

```tsx
import { prepareSessionTransfer } from '@clerk/expo/native-to-web'
```

## Usage

`prepareSessionTransfer()` has the following function signature:

```ts
function prepareSessionTransfer(params: PrepareSessionTransferParams): Promise<SessionTransfer>
```

### Parameters

`prepareSessionTransfer()` accepts the following parameters (`PrepareSessionTransferParams`):

| Name         | Type                   | Description                                                                                                                                                                   |
| ------------ | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| destination  | string                 | The page to open, as an absolute URL. Outside development instances, it must use HTTPS. In production, it must share a root domain with one of your Clerk instance's domains. |
| presentation | 'webview' | 'browser' | Where you'll open the link. Use 'webview' for a WebView that your app renders, and 'browser' for the system browser or an in-app browser tab.                                 |

### Returns

`prepareSessionTransfer()` returns a `Promise` that resolves to an object with the following properties (`SessionTransfer`):

| Name      | Type   | Description                                                                                                                                             |
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| expiresAt | Date   | When the link stops working.                                                                                                                            |
| url       | string | The one-time sign-in link. It isn't enumerable, so JSON.stringify and object spread leave it out. Debuggers can still show it, so don't log the object. |

The `Promise` rejects with a [SessionTransferError](https://clerk.com/docs/expo/reference/is-session-transfer-error.md#sessiontransfererror) when Clerk can't create the link.

## Open the link on Android

On Android, Clerk only accepts the link when the intent that opens it names your app as the referrer. Set `android.intent.extra.REFERRER_NAME` to `android-app://<your-package-name>` on that intent. Otherwise the sign-in fails with the `cross_site_request` error code.

[`expo-web-browser`](https://docs.expo.dev/versions/latest/sdk/webbrowser/) Custom Tabs can't set the referrer, so they can't open the link. Use [openInBrowser()](https://clerk.com/docs/expo/reference/open-in-browser.md), which sets it for you.

> On Android, the sign-in link opens in your app instead of the browser if your app has a verified App Link that matches it. The link's path is `/v1/session_transfers/redeem` on your Frontend API URL. The intent filter in the [passkeys setup](https://clerk.com/docs/expo/reference/passkeys.md) matches every path on that host, so it matches the link, and the user isn't signed in on the web.
>
> To fix this, narrow the intent filter with `pathPrefix` or `pathPattern` to the paths that your app handles, or remove it if your app doesn't open links on that host. Keep your Android app registered on the [**Native applications**](https://dashboard.clerk.com/~/native-applications) page, which serves the `assetlinks.json` file.

## Example

The following example opens the reports page of a web app in an in-app browser on iOS.

```ts
import { prepareSessionTransfer } from '@clerk/expo/native-to-web'
import * as WebBrowser from 'expo-web-browser'

const transfer = await prepareSessionTransfer({
  destination: 'https://app.example.com/reports',
  presentation: 'browser',
})
await WebBrowser.openBrowserAsync(transfer.url)
```

The in-app browser keeps its cookies separate from Safari, so the user is signed in only inside the in-app browser.

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
