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() instead. For the default browser, use openInBrowser().
For setup steps, see Open your web app signed in from a native app.
Import the function from the @clerk/expo/native-to-web subpath:
import { prepareSessionTransfer } from '@clerk/expo/native-to-web'Usage
prepareSessionTransfer() has the following function signature:
function prepareSessionTransfer(params: PrepareSessionTransferParams): Promise<SessionTransfer>Parameters
prepareSessionTransfer() accepts the following parameters (PrepareSessionTransferParams):
- Name
destination- Type
string- Description
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.
- Name
presentation- Type
'webview' | 'browser'- Description
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
expiresAt- Type
Date- Description
When the link stops working.
- Name
url- Type
string- Description
The one-time sign-in link. It isn't enumerable, so
JSON.stringifyand object spread leave it out. Debuggers can still show it, so don't log the object.
The Promise rejects with a 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 Custom Tabs can't set the referrer, so they can't open the link. Use openInBrowser(), which sets it for you.
Example
The following example opens the reports page of a web app in an in-app browser on iOS.
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.
Feedback
Last updated on