Introduction

On mobile devices, Descope supports running flows for initial and post authentication. With post authentication, or authenticated, flows, we support implementation of functionality like 'step up' and 'update user.' In this article, we explain how this is implemented.

Starting an Authenticated Flow

Starting an authenticated flow is similar to a unauthenticated or initial authentication flow, it simply requires the flow to be run's id and the refresh JWT of the currently authenticated user, in addition to the existing parameters.

React NativeSwiftKotlin
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)