FlowsUse Cases
Authenticated Flows
Descope supports running initial and post-authentication flows on mobile devices.
Post-authentication or authenticated flows enable functionality like step up authentication and update user. This article explains how to implement them.
Starting an Authenticated Flow
Authenticated flows work like unauthenticated or initial authentication flows. The difference is that you must also pass the Flow ID and the currently authenticated user's refresh JWT.
import { useFlow } from '@descope/react-native-sdk'
const flow = useFlow()
const { session, manageSession } = useSession()
try {
// When starting a flow for an authenticated user, provide the authentication info
let flowAuthentication = undefined
if (session) {
const flowAuthentication = {
/** The flow ID about to be run. */
flowId: 'flow-id',
/** The refresh JWT from an active descope session */
refreshJwt: session.refreshJwt,
}
}
// Some Android browsers (eg. Opera)
// don't support App Link redirects by default.
// We use the backup Custom Scheme in this case
const backupCustomScheme = "";
const resp = await flow.start('<URL_FOR_FLOW_IN_SETUP_#1>', '<URL_FOR_APP_LINK_IN_SETUP_#2>', backupCustomScheme, flowAuthentication)
await manageSession(resp.data)
} catch (e) {
// handle errors
}do {
let flowAuthentication = Authentication(
flowId: 'flow-id',
refreshJwt: 'refresh-jwt'
)
let runner = DescopeFlowRunner(flowURL: "https://example.com/flows/signup", flowAuthentication: flowAuthentication)
let authResponse = try await Descope.flow.start(runner: runner, )
let session = DescopeSession(from: authResponse)
Descope.sessionManager.manageSession(session)
showHomeScreen()
} catch DescopeError.flowCancelled {
// do nothing
} catch {
showErrorAlert(error)
}val runner = Descope.flow.create(
flowUrl = "<URL_FOR_FLOW_IN_SETUP_#1>",
deepLinkUrl = "<URL_FOR_APP_LINK_IN_SETUP_#2>",
backupCustomScheme = "<OPTIONAL_CUSTOM_SCHEME_FROM_SETUP_#2>"
)
// When starting a flow for an authenticated user, provide the authentication info
Descope.sessionManager.session?.run {
runner.flowAuthentication("flow-id", refreshJwt)
}
// Starting an authentication flow
runner.start(this@MainActivity) Was this helpful?