@ory/nextjs
Version:
This library was generated with [Nx](https://nx.dev).
1 lines • 22.3 kB
Source Map (JSON)
{"version":3,"sources":["../../src/utils/sdk.ts","../../src/pages/client.ts","../../src/pages/utils.ts","../../src/utils/rewrite.ts","../../src/utils/utils.ts","../../src/pages/flow.ts","../../src/pages/registration.ts","../../src/pages/verification.ts","../../src/pages/recovery.ts","../../src/pages/login.ts","../../src/pages/settings.ts","../../src/pages/logout.ts"],"names":["useRouter","flow","FlowType","useState","useEffect"],"mappings":";;;;;;;;;AAGO,SAAS,SAAY,GAAA;AAC1B,EAAI,IAAA,OAAA;AAEJ,EAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,yBAAyB,CAAG,EAAA;AAC1C,IAAU,OAAA,GAAA,OAAA,CAAQ,IAAI,yBAAyB,CAAA;AAAA;AAGjD,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAGF,EAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,KAAA,EAAO,EAAE,CAAA;AAClC;AAEO,SAAS,YAAe,GAAA;AAC7B,EACE,OAAA,CAAC,YAAc,EAAA,MAAM,CAAE,CAAA,OAAA;AAAA,IACrB,QAAQ,GAAI,CAAA,YAAY,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAK,IAAA;AAAA,GACtD,GAAA,CAAA,CAAA;AAER;AAEO,SAAS,iCAAiC,OAE9C,EAAA;AACD,EAAA,IAAI,cAAgB,EAAA;AAElB,IAAA,OAAO,SAAU,EAAA;AAAA;AAGnB,EAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,YAAY,CAAG,EAAA;AAM7B,IAAA,IAAI,CAAC,YAAa,EAAA,IAAK,OAAQ,CAAA,GAAA,CAAI,YAAY,CAAG,EAAA;AAChD,MAAO,OAAA,CAAA,QAAA,EAAW,QAAQ,GAAI,CAAA,YAAY,CAAC,CAAG,CAAA,CAAA,OAAA,CAAQ,OAAO,EAA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QAAA;AAAA,EACT,CAAC,MAA4B,KAAA;AAC3B,IAAO,OAAA,wBAAA,GAA2B,4BAA6B,CAAA;AAAA,MAC7D,QAAU,EAAA,MAAA,CAAO,GAAI,CAAA,WAAW,CAAK,IAAA,KAAA,CAAA;AAAA,MACrC,MAAQ,EAAA,MAAA,CAAO,GAAI,CAAA,QAAQ,CAAK,IAAA,KAAA;AAAA,KACjC,CAAA;AAAA,GACH;AAAA,EACA,CAAC,EAAO,KAAA,wBAAA,GAA2B,kBAAmB,CAAA,EAAE,IAAI;AAC9D;ACTO,SAAS,aAAgB,GAAA;AAC9B,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIC,SAAiC,KAAS,CAAA,CAAA;AAElE,EAAA,MAAM,aAAa,YAAY;AAC7B,IAAA,MAAMF,QAAO,MAAM,wBAAA,EAA2B,CAAA,uBAAA,CAAwB,EAAE,CAAA;AACxE,IAAA,OAAA,CAAQA,KAAI,CAAA;AAAA,GACd;AAEA,EAAAG,UAAU,MAAM;AACd,IAAA,IAAI,CAAC,IAAM,EAAA;AACT,MAAA,KAAK,UAAW,EAAA;AAAA;AAClB,GACF,EAAG,EAAE,CAAA;AAEL,EAAO,OAAA,IAAA;AACT","file":"index.mjs","sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nexport function orySdkUrl() {\n let baseUrl\n\n if (process.env[\"NEXT_PUBLIC_ORY_SDK_URL\"]) {\n baseUrl = process.env[\"NEXT_PUBLIC_ORY_SDK_URL\"]\n }\n\n if (!baseUrl) {\n throw new Error(\n \"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` to your Ory Network SDK URL.\",\n )\n }\n\n return baseUrl.replace(/\\/$/, \"\")\n}\n\nexport function isProduction() {\n return (\n [\"production\", \"prod\"].indexOf(\n process.env[\"VERCEL_ENV\"] || process.env[\"NODE_ENV\"] || \"\",\n ) > -1\n )\n}\n\nexport function guessPotentiallyProxiedOrySdkUrl(options?: {\n knownProxiedUrl?: string\n}) {\n if (isProduction()) {\n // In production, we use the production custom domain\n return orySdkUrl()\n }\n\n if (process.env[\"VERCEL_ENV\"]) {\n // We are in vercel\n\n // The domain name of the generated deployment URL. Example: *.vercel.app. The value does not include the protocol scheme https://.\n //\n // This is only available for preview deployments on Vercel.\n if (!isProduction() && process.env[\"VERCEL_URL\"]) {\n return `https://${process.env[\"VERCEL_URL\"]}`.replace(/\\/$/, \"\")\n }\n\n // This is sometimes set by the render server.\n if (process.env[\"__NEXT_PRIVATE_ORIGIN\"]) {\n return process.env[\"__NEXT_PRIVATE_ORIGIN\"].replace(/\\/$/, \"\")\n }\n }\n\n // Unable to figure out the SDK URL. Either because we are not using Vercel or because we are on a local machine.\n // Let's try to use the window location.\n if (typeof window !== \"undefined\") {\n return window.location.origin\n }\n\n if (options?.knownProxiedUrl) {\n return options.knownProxiedUrl\n }\n\n // We tried everything. Let's use the SDK URL.\n const final = orySdkUrl()\n console.warn(\n `Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL \"${final}\". This is likely not what you want for local development and your authentication and login may not work.`,\n )\n\n return final\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\nimport { Configuration, FrontendApi } from \"@ory/client-fetch\"\n\nimport { guessPotentiallyProxiedOrySdkUrl } from \"../utils/sdk\"\n\nexport const clientSideFrontendClient = () =>\n new FrontendApi(\n new Configuration({\n headers: {\n Accept: \"application/json\",\n },\n credentials: \"include\",\n basePath: guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n }),\n }),\n )\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { FlowType, OnRedirectHandler } from \"@ory/client-fetch\"\nimport { guessPotentiallyProxiedOrySdkUrl } from \"../utils/sdk\"\nimport { useRouter } from \"next/router\"\n\nexport function onValidationError<T>(value: T): T {\n return value\n}\n\nexport const toBrowserEndpointRedirect = (\n params: URLSearchParams,\n flowType: FlowType,\n) =>\n guessPotentiallyProxiedOrySdkUrl({\n knownProxiedUrl: window.location.origin,\n }) +\n \"/self-service/\" +\n flowType.toString() +\n \"/browser?\" +\n new URLSearchParams(params).toString()\n\nexport const handleRestartFlow =\n (searchParams: URLSearchParams, flowType: FlowType) => () => {\n window.location.assign(toBrowserEndpointRedirect(searchParams, flowType))\n }\n\nexport function useOnRedirect(): OnRedirectHandler {\n const router = useRouter()\n return (url: string, external: boolean) => {\n if (external) {\n window.location.assign(url)\n } else {\n void router.push(url)\n }\n }\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { OryConfig } from \"../types\"\nimport { joinUrlPaths } from \"./utils\"\nimport { orySdkUrl } from \"./sdk\"\n\nexport function rewriteUrls(\n source: string,\n matchBaseUrl: string,\n selfUrl: string,\n config: OryConfig,\n) {\n for (const [_, [matchPath, replaceWith]] of [\n // TODO load these dynamically from the project config\n [\"/ui/recovery\", config.override?.recoveryUiPath],\n [\"/ui/registration\", config.override?.registrationUiPath],\n [\"/ui/login\", config.override?.loginUiPath],\n [\"/ui/verification\", config.override?.verificationUiPath],\n [\"/ui/settings\", config.override?.settingsUiPath],\n [\"/ui/welcome\", config.override?.defaultRedirectUri],\n ].entries()) {\n const match = joinUrlPaths(matchBaseUrl, matchPath || \"\")\n if (replaceWith && source.startsWith(match)) {\n source = source.replaceAll(\n match,\n new URL(replaceWith, selfUrl).toString(),\n )\n }\n }\n return source.replaceAll(\n matchBaseUrl.replace(/\\/$/, \"\"),\n new URL(selfUrl).toString().replace(/\\/$/, \"\"),\n )\n}\n\n/**\n * Rewrites Ory SDK URLs in JSON responses (objects, arrays, strings) with the provided proxy URL.\n *\n * If `proxyUrl` is provided, the SDK URL is replaced with the proxy URL.\n *\n * @param obj - The object to rewrite\n * @param proxyUrl - The proxy URL to replace the SDK URL with\n */\nexport function rewriteJsonResponse<T extends object>(\n obj: T,\n proxyUrl?: string,\n): T {\n return Object.fromEntries(\n Object.entries(obj)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => {\n if (Array.isArray(value)) {\n // Recursively process each item in the array\n return [\n key,\n value\n .map((item) => {\n if (typeof item === \"object\" && item !== null) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return rewriteJsonResponse(item, proxyUrl)\n } else if (typeof item === \"string\" && proxyUrl) {\n return item.replaceAll(orySdkUrl(), proxyUrl)\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return item\n })\n .filter((item) => item !== undefined),\n ]\n } else if (typeof value === \"object\" && value !== null) {\n // Recursively remove undefined in nested objects\n return [key, rewriteJsonResponse(value, proxyUrl)]\n } else if (typeof value === \"string\" && proxyUrl) {\n // Replace SDK URL with the provided proxy URL\n return [key, value.replaceAll(orySdkUrl(), proxyUrl)]\n }\n return [key, value]\n }),\n ) as T\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\nimport { parse, splitCookiesString } from \"set-cookie-parser\"\nimport { serialize, SerializeOptions } from \"cookie\"\n\nimport { FlowParams, OryConfig, QueryParams } from \"../types\"\nimport { guessCookieDomain } from \"./cookie\"\nimport { defaultForwardedHeaders } from \"./headers\"\nimport { ApiResponse } from \"@ory/client-fetch\"\nimport { rewriteJsonResponse } from \"./rewrite\"\n\nexport function onValidationError<T>(value: T): T {\n return value\n}\n\nexport async function toFlowParams(\n params: QueryParams,\n getCookieHeader: () => Promise<string | undefined>,\n): Promise<FlowParams> {\n return {\n id: params[\"flow\"]?.toString() ?? \"\",\n cookie: await getCookieHeader(),\n return_to: params[\"return_to\"]?.toString() ?? \"\",\n }\n}\nexport function processSetCookieHeaders(\n protocol: string,\n fetchResponse: Response,\n options: OryConfig,\n requestHeaders: Headers,\n) {\n const isTls =\n protocol === \"https:\" || requestHeaders.get(\"x-forwarded-proto\") === \"https\"\n\n const forwarded = requestHeaders.get(\"x-forwarded-host\")\n const host = forwarded ? forwarded : requestHeaders.get(\"host\")\n const domain = guessCookieDomain(host ?? \"\", options)\n\n return parse(\n splitCookiesString(fetchResponse.headers.get(\"set-cookie\") || \"\"),\n )\n .map((cookie) => ({\n ...cookie,\n domain,\n secure: isTls,\n encode: (v: string) => v,\n }))\n .map(({ value, name, ...options }) =>\n serialize(name, value, options as SerializeOptions),\n )\n}\n\nexport function filterRequestHeaders(\n headers: Headers,\n forwardAdditionalHeaders?: string[],\n): Headers {\n const filteredHeaders = new Headers()\n\n headers.forEach((value, key) => {\n const isValid =\n defaultForwardedHeaders.includes(key) ||\n (forwardAdditionalHeaders ?? []).includes(key)\n if (isValid) filteredHeaders.set(key, value)\n })\n\n return filteredHeaders\n}\n\nexport function joinUrlPaths(baseUrl: string, relativeUrl: string): string {\n const base = new URL(baseUrl)\n const relative = new URL(relativeUrl, baseUrl)\n\n relative.pathname =\n base.pathname.replace(/\\/$/, \"\") +\n \"/\" +\n relative.pathname.replace(/^\\//, \"\")\n\n return new URL(relative.toString(), baseUrl).href\n}\n\nexport function toValue<T extends object>(res: ApiResponse<T>): Promise<T> {\n // Remove all undefined values from the response (array and object) using lodash:\n // Remove all (nested) undefined values from the response using lodash\n return res.value().then((v) => rewriteJsonResponse(v))\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { FlowType, handleFlowError } from \"@ory/client-fetch\"\nimport { useEffect, useState } from \"react\"\nimport { useRouter } from \"next/router\"\nimport { useSearchParams } from \"next/navigation\"\nimport { handleRestartFlow, onValidationError, useOnRedirect } from \"./utils\"\nimport { toValue } from \"../utils/utils\"\nimport * as runtime from \"@ory/client-fetch/src/runtime\"\n\ninterface Flow {\n id: string\n}\n\nexport function createUseFlowFactory<T extends Flow>(\n flowType: FlowType,\n createFlow: (params: URLSearchParams) => Promise<runtime.ApiResponse<T>>,\n getFlow: (id: string) => Promise<runtime.ApiResponse<T>>,\n): () => T | null | void {\n return () => {\n const [flow, setFlow] = useState<T>()\n const router = useRouter()\n const searchParams = useSearchParams()\n const onRestartFlow = handleRestartFlow(searchParams, flowType)\n const onRedirect = useOnRedirect()\n\n const errorHandler = handleFlowError({\n onValidationError,\n onRestartFlow,\n onRedirect,\n })\n\n const handleSetFlow = async (flow: T) => {\n setFlow(flow)\n\n // Use the router to update the `flow` search parameter only\n await router.replace({\n query: { flow: flow.id },\n })\n return\n }\n\n useEffect(() => {\n const id = searchParams.get(\"flow\")\n\n // If the router is not ready yet, or we already have a flow, do nothing.\n if (!router.isReady || flow !== undefined) {\n return\n }\n\n if (!id) {\n createFlow(searchParams)\n .then(toValue)\n .then(handleSetFlow)\n .catch(errorHandler)\n return\n }\n\n getFlow(id).then(toValue).then(handleSetFlow).catch(errorHandler)\n }, [searchParams, router, router.isReady, flow])\n\n return flow\n }\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { clientSideFrontendClient } from \"./client\"\nimport { createUseFlowFactory } from \"./flow\"\nimport { FlowType } from \"@ory/client-fetch\"\n\nexport const useRegistrationFlow = createUseFlowFactory(\n FlowType.Registration,\n (params: URLSearchParams) => {\n return clientSideFrontendClient().createBrowserRegistrationFlowRaw({\n returnTo: params.get(\"return_to\") ?? undefined,\n loginChallenge: params.get(\"registration_challenge\") ?? undefined,\n afterVerificationReturnTo:\n params.get(\"after_verification_return_to\") ?? undefined,\n organization: params.get(\"organization\") ?? undefined,\n })\n },\n (id) => clientSideFrontendClient().getRegistrationFlowRaw({ id }),\n)\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { clientSideFrontendClient } from \"./client\"\nimport { createUseFlowFactory } from \"./flow\"\nimport { FlowType } from \"@ory/client-fetch\"\n\nexport const useVerificationFlow = createUseFlowFactory(\n FlowType.Verification,\n (params: URLSearchParams) => {\n return clientSideFrontendClient().createBrowserVerificationFlowRaw({\n returnTo: params.get(\"return_to\") ?? undefined,\n })\n },\n (id) => clientSideFrontendClient().getVerificationFlowRaw({ id }),\n)\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { clientSideFrontendClient } from \"./client\"\nimport { createUseFlowFactory } from \"./flow\"\nimport { FlowType } from \"@ory/client-fetch\"\n\nexport const useRecoveryFlow = createUseFlowFactory(\n FlowType.Recovery,\n (params: URLSearchParams) => {\n return clientSideFrontendClient().createBrowserRecoveryFlowRaw({\n returnTo: params.get(\"return_to\") ?? undefined,\n })\n },\n (id) => clientSideFrontendClient().getRecoveryFlowRaw({ id }),\n)\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { clientSideFrontendClient } from \"./client\"\nimport { createUseFlowFactory } from \"./flow\"\nimport { FlowType } from \"@ory/client-fetch\"\n\nexport const useLoginFlow = createUseFlowFactory(\n FlowType.Login,\n (params: URLSearchParams) => {\n return clientSideFrontendClient().createBrowserLoginFlowRaw({\n refresh: params.get(\"refresh\") === \"true\",\n aal: params.get(\"aal\") ?? undefined,\n returnTo: params.get(\"return_to\") ?? undefined,\n cookie: params.get(\"cookie\") ?? undefined,\n loginChallenge: params.get(\"login_challenge\") ?? undefined,\n organization: params.get(\"organization\") ?? undefined,\n via: params.get(\"via\") ?? undefined,\n })\n },\n (id) => clientSideFrontendClient().getLoginFlowRaw({ id }),\n)\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { FlowType } from \"@ory/client-fetch\"\nimport { createUseFlowFactory } from \"./flow\"\nimport { clientSideFrontendClient } from \"./client\"\n\nexport const useSettingsFlow = createUseFlowFactory(\n FlowType.Settings,\n (params: URLSearchParams) => {\n return clientSideFrontendClient().createBrowserSettingsFlowRaw({\n returnTo: params.get(\"return_to\") ?? undefined,\n cookie: params.get(\"cookie\") ?? undefined,\n })\n },\n (id) => clientSideFrontendClient().getSettingsFlowRaw({ id }),\n)\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nimport { LogoutFlow } from \"@ory/client-fetch\"\nimport { clientSideFrontendClient } from \"./client\"\nimport { useEffect, useState } from \"react\"\n\nexport function useLogoutFlow() {\n const [flow, setFlow] = useState<LogoutFlow | undefined>(undefined)\n\n const createFlow = async () => {\n const flow = await clientSideFrontendClient().createBrowserLogoutFlow({})\n setFlow(flow)\n }\n\n useEffect(() => {\n if (!flow) {\n void createFlow()\n }\n }, [])\n\n return flow\n}\n"]}