Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 13, 2024
1 parent 79038dc commit db3416a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 83 deletions.
9 changes: 3 additions & 6 deletions examples/nextjs-app-router/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,7 +19,7 @@ export default async function LoginPage(props: OryPageParams) {
return (
<Login
flow={flow}
config={oryAppRouterConfig(config)}
config={enhanceConfig(config)}
components={{
Card: {
Header: CardHeader,
Expand Down
5 changes: 3 additions & 2 deletions examples/nextjs-pages-router/pages/auth/registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
"use client"
import { Registration } from "@ory/elements-react/theme"
import { oryPageRouterConfig, useRegistrationFlow } from "@ory/nextjs/pages"
import { useRegistrationFlow } from "@ory/nextjs/pages"
import { enhanceConfig } from "@ory/nextjs"
import "@ory/elements-react/theme/styles.css"

import config from "@/ory.config"
Expand All @@ -18,7 +19,7 @@ export default function RegistrationPage() {
<div className="pt-4">
<Registration
flow={flow}
config={oryPageRouterConfig(config)}
config={enhanceConfig(config)}
components={{
Card: {},
}}
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"private": false,
"dependencies": {
"@ory/client-fetch": "^1.15.6",
"@ory/elements-react": "*",
"cookie": "^1.0.1",
"parse-domain": "^8.2.2",
"psl": "^1.10.0",
Expand Down
34 changes: 0 additions & 34 deletions packages/nextjs/src/app/config.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/nextjs/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export type { OryConfig } from "./types"
export { enhanceConfig } from "./utils/config"
34 changes: 0 additions & 34 deletions packages/nextjs/src/pages/config.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/nextjs/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
// SPDX-License-Identifier: Apache-2.0
"use client"
export { useRegistrationFlow } from "./registration"
export { oryPageRouterConfig } from "./config"
29 changes: 25 additions & 4 deletions packages/nextjs/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -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<OryConfig>,
): 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: {
Expand Down

0 comments on commit db3416a

Please sign in to comment.