Skip to Content
Omnibase

Flow Routing

Flow Routing

Components and utilities for handling Ory Kratos authentication flows including login, registration, recovery, verification, and settings.

FlowRouterProps

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:139

Props for the FlowRouter component

Configuration object for the FlowRouter component that handles dynamic authentication flow routing in Next.js applications.

Since

0.5.1

Properties

PropertyTypeDefault valueDescriptionDefined in
flowMapFlowMapundefinedMap of flow types to their corresponding React component render functionssdk/framework/nextjs/src/auth/flow-router.ts:143
onNotFound?ReactNodeundefinedComponent to render when the requested flow type is not found or not supportedsdk/framework/nextjs/src/auth/flow-router.ts:145
paramsPromise<{ flow: string[]; }>undefinedNext.js params promise containing the flow type from dynamic route segmentssdk/framework/nextjs/src/auth/flow-router.ts:141
returnTo?string"/"URL to redirect to after flow completionsdk/framework/nextjs/src/auth/flow-router.ts:154
searchParamsPromise<{ [key: string]: string | string[] | undefined; }>undefinedPromise resolving to search parameters from the request URLsdk/framework/nextjs/src/auth/flow-router.ts:149
urlstringundefinedBase URL path for authentication flows (e.g., '/auth')sdk/framework/nextjs/src/auth/flow-router.ts:147

FlowMap

type FlowMap = {
  error?: (error) => ReactNode;
  login?: (flow) => ReactNode;
  onboarding?: (flow) => ReactNode;
  recovery?: (flow) => ReactNode;
  registration?: (flow) => ReactNode;
  settings?: (flow) => ReactNode;
  verification?: (flow) => ReactNode;
};

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:39

Maps auth flow types to their corresponding React component functions

This type defines the structure for mapping authentication flow types to render functions. Each property represents a different authentication flow, and its value is a function that receives the flow data and returns a React component to render.

Example

const flowMap: FlowMap = {
  login: (flow) => <LoginForm flow={flow} />,
  registration: (flow) => <RegisterForm flow={flow} />,
  recovery: (flow) => <RecoveryForm flow={flow} />
};

Since

0.5.1

Properties

error()?
optional error: (error) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:53

Function that takes a FlowError and returns a component for displaying authentication errors

Parameters
ParameterType
errorFlowError
Returns

ReactNode

login()?
optional login: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:41

Function that takes a LoginFlow and returns a component for user authentication

Parameters
ParameterType
flowLoginFlow
Returns

ReactNode

onboarding()?
optional onboarding: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:51

Function that takes any flow object and returns a component for custom onboarding

Parameters
ParameterType
flowany
Returns

ReactNode

recovery()?
optional recovery: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:45

Function that takes a RecoveryFlow and returns a component for password recovery

Parameters
ParameterType
flowRecoveryFlow
Returns

ReactNode

registration()?
optional registration: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:43

Function that takes a RegistrationFlow and returns a component for user registration

Parameters
ParameterType
flowRegistrationFlow
Returns

ReactNode

settings()?
optional settings: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:49

Function that takes a SettingsFlow and returns a component for user settings management

Parameters
ParameterType
flowSettingsFlow
Returns

ReactNode

verification()?
optional verification: (flow) => ReactNode;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:47

Function that takes a VerificationFlow and returns a component for email/account verification

Parameters
ParameterType
flowVerificationFlow
Returns

ReactNode


FlowObject

type FlowObject = 
  | LoginFlow
  | RecoveryFlow
  | RegistrationFlow
  | SettingsFlow
  | VerificationFlow;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:66

Union type for all possible flow objects

Represents any valid authentication flow object that can be returned by the Ory Kratos authentication system.

Since

0.5.1


FlowRouter()

function FlowRouter(props): Promise<
  | ReactElement<unknown, string | JSXElementConstructor<any>>
  | Iterable<ReactNode, any, any>
| AwaitedReactNode>;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:212

Routes authentication flows to their corresponding components based on URL parameters

FlowRouter is a server component that dynamically renders the appropriate authentication UI based on the URL path. It fetches the flow data from Ory Kratos and passes it to the corresponding render function from the flowMap. This component is designed for Next.js 13+ App Router with catch-all routes.

The router extracts the flow type from the URL (e.g., /auth/login → login), retrieves the flow object, and invokes the matching render function with the flow data.

Parameters

ParameterTypeDescription
propsFlowRouterPropsConfiguration props for the router

Returns

Promise< | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | AwaitedReactNode>

Promise resolving to the rendered component for the current flow

Example

// In your app/auth/[...flow]/page.tsx
import { FlowRouter } from '@omnibase/nextjs/auth';
import { LoginForm, RegistrationForm, RecoveryForm } from '@omnibase/shadcn';

export default function AuthPage({
  params,
  searchParams
}: {
  params: Promise<{ flow: string[] }>;
  searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
  return (
    <FlowRouter
      params={params}
      searchParams={searchParams}
      url="/auth"
      returnTo="/"
      flowMap={{
        login: (flow) => <LoginForm flow={flow} register_url="/auth/registration" />,
        registration: (flow) => <RegistrationForm flow={flow} login_url="/auth/login" />,
        recovery: (flow) => <RecoveryForm flow={flow} />,
      }}
      onNotFound={<div>Authentication flow not supported</div>}
    />
  );
}

Since

0.5.1


getFlow()

function getFlow(flowType, props): Promise<FlowObject | null>;

Defined in: sdk/framework/nextjs/src/auth/flow-router.ts:104

Retrieves the appropriate flow object based on the flow type

This function acts as a router for authentication flows, delegating to the appropriate flow retrieval function based on the flow type. It's used internally by FlowRouter but can also be used independently for custom flow handling.

Parameters

ParameterTypeDescription
flowTypekeyof FlowMapThe type of flow to retrieve (login, registration, recovery, verification, settings, onboarding)
propsGetFlowPropsConfiguration object containing URL and search parameters

Returns

Promise<FlowObject | null>

Promise that resolves to the corresponding flow object or null if not found/supported

Example

// Retrieve a login flow
const loginFlow = await getFlow('login', {
  url: '/auth/login',
  searchParams: Promise.resolve({ flow: 'abc123' })
});

if (loginFlow) {
  console.log('Login flow retrieved:', loginFlow.id);
}

Since

0.5.1

On this page