isSessionTransferError()
The isSessionTransferError() function returns true when an error is a SessionTransferError. Use it to branch on the error's code when openInBrowser() or prepareSessionTransfer() rejects. useAuthenticatedWebView() 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 SessionTransferErrorExample
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 itsstatusandretryAfter.
- Name
code- Type
SessionTransferErrorCode- Description
Why the session transfer failed. See the error codes.
- Name
name- Type
'SessionTransferError'- Description
The name of the error.
Error codes
The SDK sets the following codes while creating or opening the link:
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:
Feedback
Last updated on