diff --git a/examples/nextjs-app-router/app/auth/login/page.tsx b/examples/nextjs-app-router/app/auth/login/page.tsx index 1e1568ae..a6139744 100644 --- a/examples/nextjs-app-router/app/auth/login/page.tsx +++ b/examples/nextjs-app-router/app/auth/login/page.tsx @@ -2,12 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import { Login } from "@ory/elements-react/theme" -import { - getLoginFlow, - oryAppRouterConfig, - OryPageParams, -} from "@ory/nextjs/app" +import { getLoginFlow, OryPageParams } from "@ory/nextjs/app" import "@ory/elements-react/theme/styles.css" +import { enhanceConfig } from "@ory/nextjs" import config from "@/ory.config" import CardHeader from "@/app/auth/login/card-header" @@ -22,7 +19,7 @@ export default async function LoginPage(props: OryPageParams) { return ( , - forceSdkUrl?: string, -): OryClientConfiguration { - let sdkUrl = - forceSdkUrl ?? - process.env["NEXT_PUBLIC_ORY_SDK_URL"] ?? - process.env["ORY_SDK_URL"] - - if (!forceSdkUrl && !isProduction()) { - if (process.env["__NEXT_PRIVATE_ORIGIN"]) { - sdkUrl = process.env["__NEXT_PRIVATE_ORIGIN"].replace(/\/$/, "") - } else if (process.env["VERCEL_URL"]) { - sdkUrl = `https://${process.env["VERCEL_URL"]}`.replace(/\/$/, "") - } else if (typeof window !== "undefined") { - sdkUrl = window.location.origin - } - } - - if (!sdkUrl) { - throw new Error( - "Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or force the SDK URL using `useOryConfig(config, 'https://my-ory-sdk-url.com')`.", - ) - } - - return baseUseOryConfig(sdkUrl, config) -} diff --git a/packages/nextjs/src/app/index.ts b/packages/nextjs/src/app/index.ts index 0b6efc5f..b431295d 100644 --- a/packages/nextjs/src/app/index.ts +++ b/packages/nextjs/src/app/index.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 "use server" export { getLoginFlow } from "./login" -export { oryAppRouterConfig } from "./config" export interface OryPageParams { searchParams: URLSearchParams diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index c4593eea..d5e3aa00 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -2,3 +2,4 @@ // SPDX-License-Identifier: Apache-2.0 export type { OryConfig } from "./types" +export { enhanceConfig } from "./utils/config" diff --git a/packages/nextjs/src/pages/config.ts b/packages/nextjs/src/pages/config.ts deleted file mode 100644 index 1dd06ce4..00000000 --- a/packages/nextjs/src/pages/config.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © 2024 Ory Corp -// SPDX-License-Identifier: Apache-2.0 -import { OryConfig } from "../types" -import { OryClientConfiguration } from "@ory/elements-react" -import { isProduction } from "../utils/sdk" -import { useOryConfig as baseUseOryConfig } from "../utils/config" - -export function oryPageRouterConfig( - config: Partial, - forceSdkUrl?: string, -): OryClientConfiguration { - let sdkUrl = - forceSdkUrl ?? - process.env["NEXT_PUBLIC_ORY_SDK_URL"] ?? - process.env["ORY_SDK_URL"] - - if (!forceSdkUrl && !isProduction()) { - if (process.env["__NEXT_PRIVATE_ORIGIN"]) { - sdkUrl = process.env["__NEXT_PRIVATE_ORIGIN"].replace(/\/$/, "") - } else if (process.env["VERCEL_URL"]) { - sdkUrl = `https://${process.env["VERCEL_URL"]}`.replace(/\/$/, "") - } else if (typeof window !== "undefined") { - sdkUrl = window.location.origin - } - } - - if (!sdkUrl) { - throw new Error( - "Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or force the SDK URL using `useOryConfig(config, 'https://my-ory-sdk-url.com')`.", - ) - } - - return baseUseOryConfig(sdkUrl, config) -} diff --git a/packages/nextjs/src/pages/index.ts b/packages/nextjs/src/pages/index.ts index b2110c60..1cb511cc 100644 --- a/packages/nextjs/src/pages/index.ts +++ b/packages/nextjs/src/pages/index.ts @@ -2,4 +2,3 @@ // SPDX-License-Identifier: Apache-2.0 "use client" export { useRegistrationFlow } from "./registration" -export { oryPageRouterConfig } from "./config" diff --git a/packages/nextjs/src/utils/config.ts b/packages/nextjs/src/utils/config.ts index 4d6ac1a9..d94d16fe 100644 --- a/packages/nextjs/src/utils/config.ts +++ b/packages/nextjs/src/utils/config.ts @@ -1,12 +1,33 @@ // Copyright © 2024 Ory Corp // SPDX-License-Identifier: Apache-2.0 import { OryConfig } from "../types" -import { OryClientConfiguration } from "@ory/elements-react" +import { isProduction } from "./sdk" -export function useOryConfig( - sdkUrl: string, +export function enhanceConfig( config: Partial, -): OryClientConfiguration { + forceSdkUrl?: string, +) { + let sdkUrl = + forceSdkUrl ?? + process.env["NEXT_PUBLIC_ORY_SDK_URL"] ?? + process.env["ORY_SDK_URL"] + + if (!forceSdkUrl && !isProduction()) { + if (process.env["__NEXT_PRIVATE_ORIGIN"]) { + sdkUrl = process.env["__NEXT_PRIVATE_ORIGIN"].replace(/\/$/, "") + } else if (process.env["VERCEL_URL"]) { + sdkUrl = `https://${process.env["VERCEL_URL"]}`.replace(/\/$/, "") + } else if (typeof window !== "undefined") { + sdkUrl = window.location.origin + } + } + + if (!sdkUrl) { + throw new Error( + "Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or force the SDK URL using `useOryConfig(config, 'https://my-ory-sdk-url.com')`.", + ) + } + return { name: config.override?.applicationName ?? "Default name", sdk: {