Configuration
Ory Elements exposes a few configuration options that can be used to configure the default behavior of the UI components. These options can be set globally or per component. This guide will cover the global configuration options available in Ory Elements.
Project configuration
The project configuration is used to configure the overall behavior of the Ory Elements UI components. It includes settings such
as the project name, redirect URLs, and UI URLs for various actions like login, registration, and recovery.
You can set the project configuration globally in your application, and it will be used by all Ory Elements components. This allows you to use the default UI but still configure certain behaviors and URLs to match your application's requirements.
Define the project configuration in your application like this:
import { ProjectConfiguration } from "@ory/elements-react"
export const projectConfig: ProjectConfiguration = {
default_redirect_url: "https://example.com/dashboard", // URL to redirect after successful login or registration
error_ui_url: "https://example.com/error", // URL to handle errors
login_ui_url: "https://example.com/login", // URL to the login page
registration_ui_url: "https://example.com/register", // URL to the registration page
recovery_ui_url: "https://example.com/recovery", // URL to the recovery page
settings_ui_url: "https://example.com/settings", // URL to the settings page
verification_ui_url: "https://example.com/verify", // URL to the verification page
name: "My Project", // the name of your project, used in the UI
logo_light_url: "https://example.com/logo-light.png", // URL to the logo
recovery_enabled: true, // controls whether the "Forgot Password" button is shown
registration_enabled: true, // controls whether the "Register" button in the footer is shown
verification_enabled: true,
}
After defining the configuration, you can pass it to the <Login />, <Registration />, <Recovery />, <Settings />, and
<Verification /> components as a prop:
import { LoginFlow } from "@ory/client-fetch"
import { Login } from "@ory/elements-react/theme"
import { projectConfig } from "./projectConfig" // import your project configuration
// Fetch or create the flow object before rendering, for example with getLoginFlow from @ory/nextjs/app.
function App({ flow }: { flow: LoginFlow }) {
return <Login flow={flow} config={{ project: projectConfig }} />
}
If you're building your own components, pass it to the OryProvider in the config prop to make it available to all Ory Elements
components. The OryProvider also requires the flow, its type, and the components to render:
import { FlowType, LoginFlow } from "@ory/client-fetch"
import { OryProvider } from "@ory/elements-react"
import { getOryComponents } from "@ory/elements-react/theme"
import { PropsWithChildren } from "react"
import { projectConfig } from "./projectConfig" // import your project configuration
function App({ flow, children }: PropsWithChildren<{ flow: LoginFlow }>) {
return (
<OryProvider config={{ project: projectConfig }} flow={flow} flowType={FlowType.Login} components={getOryComponents()}>
{children}
</OryProvider>
)
}
OryProvider has no project prop. Pass the project configuration as config={{ project: projectConfig }}.
UI URLs
To set the URLs for various UI components, you can use the following properties in the ProjectConfiguration:
const projectConfig: ProjectConfiguration = {
login_ui_url: "https://example.com/login",
registration_ui_url: "https://example.com/register",
recovery_ui_url: "https://example.com/recovery",
settings_ui_url: "https://example.com/settings",
verification_ui_url: "https://example.com/verify",
// ....
}
These will be used when the respective actions are triggered, such as when a user needs to log in, register, or recover their
account and should match the URLs of your application's UI. You can also set the error_ui_url to handle errors in a custom way:
const projectConfig: ProjectConfiguration = {
error_ui_url: "https://example.com/error",
// ....
}
Logos
To set the logo, use the logo_light_url property. The logo_dark_url property is currently unused.
const projectConfig: ProjectConfiguration = {
logo_light_url: "https://example.com/logo-light.png",
// ....
}
Locale (i18n)
The locale is not part of the ProjectConfiguration. Set it in the intl property of the OryClientConfiguration:
import { OryClientConfiguration } from "@ory/elements-react"
import { projectConfig } from "./projectConfig"
const config: OryClientConfiguration = {
intl: {
locale: "en",
},
project: projectConfig,
}
For more advanced localization options, such as providing custom translations, refer to the Internationalization guide.
Reference:
SDK configuration
The sdk configuration is used to configure the Ory SDK client that is used by Ory Elements. This includes settings such as the
URL of the Ory API. You can set the SDK configuration globally in your application, and it will be used by all Ory Elements
components. The SDK configuration is the sdk property of the OryClientConfiguration:
import { OryClientConfiguration } from "@ory/elements-react"
import { projectConfig } from "./projectConfig" // import your project configuration
export const config: OryClientConfiguration = {
sdk: {
url: "https://api.example.com", // URL of the Ory API
options: {
headers: {
"X-Custom-Header": "value", // custom headers for the SDK requests
},
middleware: [], // custom middleware for the SDK requests
// other options for the SDK requests
},
},
project: projectConfig,
}
The property is sdk.url. sdk.baseUrl and sdk.baseURL don't exist and are ignored.
If you're running against a standard Ory Network project you don't need to add any special headers or middleware. Set sdk.url to
your project's URL as listed on Project settings → Overview in the Ory Console under API endpoints.
Typically, this URL is the same as the one you use to access your Ory services, such as Ory Kratos or Ory Hydra. It is important to ensure that the base URL is correctly set to match your Ory deployment.
After defining the configuration, pass it to the flow components or to the <OryProvider> component in the config prop:
import { LoginFlow } from "@ory/client-fetch"
import { Login } from "@ory/elements-react/theme"
import { config } from "./ory.config"
function App({ flow }: { flow: LoginFlow }) {
return <Login flow={flow} config={config} />
}
Base URL
The browser has to reach Ory on a URL whose session cookies the app can read: either Ory on the same site as the app, or the Ory
middleware serving Ory on the app's own origin. Ory Elements components use the URL that the server attached to the flow or error,
then the sdk.url of their configuration.
With @ory/nextjs, the flow functions and getError attach the URL the server resolved for that request, so the components and
the server use the same URL without further configuration. SessionProvider fetches the session itself: pass it
baseUrl={await getOryBaseUrl()}.
When Ory is on the same site as the app, the URL is NEXT_PUBLIC_ORY_SDK_URL. Otherwise it is the page's origin when the
middleware handled the page and the origin is in trustedOrigins, and NEXT_PUBLIC_ORY_SDK_URL if not. No environment name such
as NODE_ENV or VERCEL_ENV changes the result, so a preview deployment, which runs a production build, resolves like local
development.
The middleware's matcher must cover every page that calls a function from @ory/nextjs/app. The default
export const config = {} does.
The Pages Router hooks run in the browser and can't see the middleware. They use NEXT_PUBLIC_ORY_SDK_URL when it is on the same
site as the page, and the page's origin otherwise.
Troubleshooting
When the browser would call Ory on another site, Ory's session cookies don't reach the app, and login or session checks fail.
@ory/nextjs then logs a warning once in the server log:
| Warning | Fix |
|---|---|
The Ory proxy handled a request for <origin>, which is not in trustedOrigins | In local development or a preview deployment, add the origin to trustedOrigins. In production, use a custom domain on the app's site. |
The app (<origin>) and Ory (<url>) are on different sites | The middleware didn't run for this page. Export it from proxy.ts (middleware.ts before Next.js 16) in the project root, or in src/ if the app uses one, and make its matcher cover the page. |
The request's Host header is not a valid origin | Configure the reverse proxy in front of the app to forward the Host header the browser sent. |
@ory/react-router and @ory/tanstack-start log the same warnings. See the troubleshooting sections of the
React Router and
TanStack Start quickstarts for the fixes.
When sdk.url is unset
If neither a URL attached by the server nor the url property in the sdk configuration is set, the base URL can be set via the
environment variable ORY_SDK_URL.
In development environments, if neither is set, Ory Elements tries to "guess" the base URL by looking at the current origin of the
page. For code that is run in the browser, the base URL is set to the current origin of the page (via window.location.origin).
Set sdk.url explicitly so that the result doesn't depend on the environment.
Next.js middleware configuration
When you use createOryMiddleware from @ory/nextjs, the
middleware proxies Ory requests through your application's own origin and tells Ory which base URL to use for redirects and
emails.
The middleware is for local development and preview deployments. It isn't supported in production: through the middleware, Ory sees every request coming from your server's address instead of your users' browsers. In production, use a custom domain on Ory Network, or serve Ory on your own domain with the Ory Enterprise License (OEL), on the same site as your application.
Trusted origins
Ory uses the reported base URL for the links in recovery and verification emails and for redirects. Set trustedOrigins to the
origins your local development server and preview deployments serve:
import { createOryMiddleware } from "@ory/nextjs/middleware"
export default createOryMiddleware({
trustedOrigins: [
// The local development server, matched exactly (scheme, host, and port).
"http://localhost:3000",
// Vercel preview deployments of the project "my-app" of the team "my-team".
"https://my-app-*-my-team.vercel.app",
],
})
An entry is an origin without a path, such as http://localhost:3000. To match several origins, use * in the host as a glob,
such as https://my-app-*-my-team.vercel.app. Each * matches one or more letters, digits, or hyphens and never a dot, so it
stays inside one part of the host name. A * can't make up the whole label right before a public suffix from the
Public Suffix List, such as vercel.app or com, so https://*.vercel.app is rejected. On a
hosting provider's domain, include your project and team in the glob, so it doesn't match other customers' deployments.
createOryMiddleware throws at startup when trustedOrigins is unset, empty, or has an invalid entry.
| Entry | Accepted | Matches |
|---|---|---|
http://localhost:3000 | Yes | http://localhost:3000 only |
https://my-app-*-my-team.vercel.app | Yes | https://my-app-git-main-my-team.vercel.app |
https://pr-*.preview.example.com | Yes | https://pr-42.preview.example.com |
localhost:3000 | No | No scheme |
http://localhost:3000/login | No | Has a path |
https://*.vercel.app | No | * is the whole label before the public suffix |
The middleware serves only the origins in trustedOrigins. For a request on any other origin, the middleware still proxies Ory's
paths, but it doesn't send the base URL to Ory, and the flow functions use the Ory SDK URL and log a warning. Don't add your
production origin: production uses a custom domain instead.
OAuth2 and OpenID Connect browser redirects, such as /oauth2/auth after a login for an OAuth2 client, stay on your Ory project's
domain. The middleware doesn't proxy these paths, and it doesn't rewrite their URLs to your app's origin.
To send the base URL, the middleware needs the ORY_PROJECT_API_TOKEN environment variable. For preview deployments, create a
dedicated API key, set it only in the preview environment, and never give it a NEXT_PUBLIC_ prefix.
Forwarded headers
The middleware forwards a fixed set of request headers to Ory and drops the rest. The set includes the browser's Origin header
and its Fetch Metadata headers (Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest, and Sec-Fetch-User), so Ory sees the same
origin signals as for a request the browser sends to Ory directly. To forward more headers, list them in
forwardAdditionalHeaders:
import { createOryMiddleware } from "@ory/nextjs/middleware"
export default createOryMiddleware({
trustedOrigins: ["https://app.example.com"],
forwardAdditionalHeaders: ["x-custom-header"],
})
Because the Origin header reaches Ory, Ory rejects API flows submitted from the browser through the middleware. Browser apps
must use browser flows; API flows are for native apps.
Cookies
The middleware removes the Domain attribute from the cookies Ory returns, so the browser sends them only to the host that set
them. To share them with other hosts under your domain, set forceCookieDomain to that domain. The browser then sends the
cookies, including the session cookie, to every host under that domain, not only the ones you intend. For example, example.com
covers app.example.com, api.example.com, and any other subdomain. Set this option only when you trust every host under the
domain. Cookies with the __Host- prefix never get a domain.
The middleware sets the Secure attribute over HTTPS, including when a proxy in front of your app reports HTTPS in the
X-Forwarded-Proto header, and otherwise keeps it as Ory sent it. The exception is a plain-HTTP request to localhost,
*.localhost, 127.0.0.1, or [::1]: the middleware removes Secure there so that every browser accepts the cookies during
local development. Any other host has to use HTTPS.