-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
626 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Recovery } from "@ory/elements-react/theme" | ||
import { getRecoveryFlow, OryPageParams } from "@ory/nextjs/app" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
|
||
import config from "@/ory.config" | ||
import CustomCardHeader from "@/components/custom-card-header" | ||
|
||
export default async function RecoveryPage(props: OryPageParams) { | ||
const flow = await getRecoveryFlow(props.searchParams) | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Recovery | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: { | ||
Header: CustomCardHeader, | ||
}, | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Registration } from "@ory/elements-react/theme" | ||
import { getRegistrationFlow, OryPageParams } from "@ory/nextjs/app" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
|
||
import config from "@/ory.config" | ||
import CustomCardHeader from "@/components/custom-card-header" | ||
|
||
export default async function RegistrationPage(props: OryPageParams) { | ||
const flow = await getRegistrationFlow(props.searchParams) | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Registration | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: {}, | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Verification } from "@ory/elements-react/theme" | ||
import { getVerificationFlow, OryPageParams } from "@ory/nextjs/app" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
|
||
import config from "@/ory.config" | ||
import CustomCardHeader from "@/components/custom-card-header" | ||
|
||
export default async function VerificationPage(props: OryPageParams) { | ||
const flow = await getVerificationFlow(props.searchParams) | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Verification | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: { | ||
Header: CustomCardHeader, | ||
}, | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
"use client" | ||
import { Login } from "@ory/elements-react/theme" | ||
import { useLoginFlow } from "@ory/nextjs/pages" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
import "@ory/elements-react/theme/styles.css" | ||
|
||
import config from "@/ory.config" | ||
|
||
export default function LoginPage() { | ||
const flow = useLoginFlow() | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="pt-4"> | ||
<Login | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: {}, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
"use client" | ||
import { Recovery } from "@ory/elements-react/theme" | ||
import { useRecoveryFlow } from "@ory/nextjs/pages" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
import "@ory/elements-react/theme/styles.css" | ||
|
||
import config from "@/ory.config" | ||
|
||
export default function RecoveryPage() { | ||
const flow = useRecoveryFlow() | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="pt-4"> | ||
<Recovery | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: {}, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
"use client" | ||
import { Verification } from "@ory/elements-react/theme" | ||
import { useVerificationFlow } from "@ory/nextjs/pages" | ||
import { enhanceConfig } from "@ory/nextjs" | ||
import "@ory/elements-react/theme/styles.css" | ||
|
||
import config from "@/ory.config" | ||
|
||
export default function VerificationPage() { | ||
const flow = useVerificationFlow() | ||
|
||
if (!flow) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="pt-4"> | ||
<Verification | ||
flow={flow} | ||
config={enhanceConfig(config)} | ||
components={{ | ||
Card: {}, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { redirect, RedirectType } from "next/navigation" | ||
import { FlowType, handleFlowError } from "@ory/client-fetch" | ||
|
||
import { getPublicUrl, onRedirect } from "./utils" | ||
import { QueryParams } from "../types" | ||
import { guessPotentiallyProxiedOrySdkUrl } from "../utils/sdk" | ||
import { onValidationError } from "../utils/utils" | ||
import { rewriteJsonResponse } from "../utils/rewrite" | ||
import * as runtime from "@ory/client-fetch/src/runtime" | ||
|
||
export async function getFlow<T extends object>( | ||
params: QueryParams | Promise<QueryParams>, | ||
fetchFlowRaw: () => Promise<runtime.ApiResponse<T>>, | ||
flowType: FlowType, | ||
): Promise<T | null | void> { | ||
const p = await params | ||
|
||
// Guess our own public url using Next.js helpers. We need the hostname, port, and protocol. | ||
const knownProxiedUrl = await getPublicUrl() | ||
|
||
const onRestartFlow = () => { | ||
return redirect( | ||
new URL( | ||
"/self-service/" + | ||
flowType.toString() + | ||
"/browser?" + | ||
params.toString(), | ||
guessPotentiallyProxiedOrySdkUrl({ | ||
knownProxiedUrl, | ||
}), | ||
).toString(), | ||
RedirectType.replace, | ||
) | ||
} | ||
|
||
if (!p["flow"]) { | ||
onRestartFlow() | ||
return | ||
} | ||
|
||
try { | ||
const rawResponse = await fetchFlowRaw() | ||
return await rawResponse | ||
.value() | ||
.then( | ||
(v: T): T => | ||
rewriteJsonResponse( | ||
v, | ||
guessPotentiallyProxiedOrySdkUrl({ knownProxiedUrl }), | ||
), | ||
) | ||
} catch (error) { | ||
const errorHandler = handleFlowError({ | ||
onValidationError, | ||
onRestartFlow, | ||
onRedirect: onRedirect, | ||
}) | ||
await errorHandler(error) | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.