Skip to main content

isSessionTransferError()

The isSessionTransferError() function returns true when an error is a SessionTransferErrorExpo Icon. Use it to branch on the error's code when openInBrowser()Expo Icon or prepareSessionTransfer()Expo Icon rejects. useAuthenticatedWebView()Expo Icon returns its SessionTransferError in error instead of throwing it.

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

import { isSessionTransferError } from '@clerk/expo/native-to-web'

Usage

isSessionTransferError() has the following function signature:

function isSessionTransferError(error: unknown): error is SessionTransferError

Example

The following example sends a signed-out user to the sign-in screen when the web app can't open.

import { isSessionTransferError, openInBrowser } from '@clerk/expo/native-to-web'
import { router } from 'expo-router'

try {
  await openInBrowser({ destination: 'https://app.example.com/settings' })
} catch (error) {
  if (isSessionTransferError(error) && error.code === 'signed_out') {
    router.replace('/sign-in')
  }
}

SessionTransferError

Every native-to-web function reports failures as a SessionTransferError. It's an Error with the following additional properties:

  • Name
    cause?
    Type
    unknown
    Description

    The original error. When the Clerk API refuses to create the link, it's the original ClerkAPIResponseError, so you can read its status and retryAfter.

  • Name
    code
    Type
    SessionTransferErrorCode
    Description

    Why the session transfer failed. See the error codesExpo Icon.

  • Name
    name
    Type
    'SessionTransferError'
    Description

    The name of the error.

Error codes

The SDK sets the following codes while creating or opening the link:

CodeDescription
unsupported_platformThe app is running on the web. Session transfer only works in native apps.
clerk_not_loadedClerk hasn't finished loading.
signed_outThe app has no active session. A session with pending session tasks also counts as signed out.
invalid_destinationdestination isn't an absolute HTTP or HTTPS URL.
missing_dependencyA package that the function needs on Android isn't installed. The error message names the package.
browser_unavailableThe operating system couldn't open the link.
load_failedThe WebView couldn't load Clerk's sign-in page or the page it redirected to.
network_errorClerk couldn't be reached, or didn't respond within 20 seconds.
unexpected_responseClerk returned a response that the SDK didn't expect.

When the Clerk API refuses to create the link, code is the first error code that the API returned. For example, feature_not_enabled means Native to Web SSO is turned off on the Clerk Dashboard's Native applications page.

When the sign-in on the web fails, code is the __clerk_error_code that Clerk redirected with. Only useAuthenticatedWebView() can report these codes. They include the following:

CodeDescription
invalid_tokenThe link isn't valid.
expiredThe link expired before anyone opened it. Links work for up to 60 seconds.
already_usedSomeone already opened the link. Each link works once.
source_session_invalidThe app's session ended, or the user can no longer sign in, such as when they're banned or locked.
impersonation_in_progressThe browser is signed in to an impersonation session. It stays in that session.
other_user_signed_inThe browser is signed in only as a different user. It stays signed in as that user.
cross_site_requestThe browser didn't treat the link as a direct navigation. On Android, this happens when the intent that opens the link doesn't name your app as the referrer.

Feedback

What did you think of this content?

Last updated on