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 12, 2024
1 parent b32f72f commit 04b3fed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build nextjs` to build the library.
Run `nx build @ory/nextjs` to build the library.

## Developing

Run `nx dev @ory/nextjs` to watch the source code for changes and continuously build the library.

## Running unit tests

Run `nx test nextjs` to execute the unit tests via [Jest](https://jestjs.io).
Run `nx test @ory/nextjs` to execute the unit tests via [Jest](https://jestjs.io).
3 changes: 2 additions & 1 deletion packages/nextjs/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

export {
useRegistrationFlow,
// getRegistrationServerSideProps,
} from "./registration"

export type {RegistrationPageProps} from "./registration"
// export type { RegistrationPageProps } from "./registration"
42 changes: 30 additions & 12 deletions packages/nextjs/src/pages/registration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

"use client"
import { useEffect, useState } from "react"
import {
FlowType,
handleFlowError,
RegistrationFlow,
} from "@ory/client-fetch"
import { FlowType, handleFlowError, RegistrationFlow } from "@ory/client-fetch"
import { useRouter } from "next/router"
import { newOryFrontendClient } from "../sdk"
import { onValidationError } from "../utils"
import { onValidationError, toValue } from "../utils"
import { useSearchParams } from "next/navigation"
import { handleRestartFlow, useOnRedirect } from "./utils"

Expand All @@ -28,6 +24,15 @@ export function useRegistrationFlow(): RegistrationFlow | null | void {
onRedirect,
})

const handleSetFlow = (flow: RegistrationFlow) => {
setFlow(flow)

// Use the router to update the `flow` search parameter only
return router.replace({
query: { flow: flow.id },
})
}

useEffect(() => {
const id = searchParams.get("flow")

Expand All @@ -37,7 +42,20 @@ export function useRegistrationFlow(): RegistrationFlow | null | void {
}

if (!id) {
onRestartFlow()
client
.createBrowserRegistrationFlowRaw({
returnTo: searchParams.get("return_to") ?? undefined,
loginChallenge: searchParams.get("login_challenge") ?? undefined,
afterVerificationReturnTo:
searchParams.get("after_verification_return_to") ?? undefined,
organization: searchParams.get("organization") ?? undefined,
})
.then(toValue)
.then((v) => {
setFlow(v)
return handleSetFlow(v)
})
.catch(errorHandler)
return
}

Expand All @@ -51,7 +69,7 @@ export function useRegistrationFlow(): RegistrationFlow | null | void {
return flow
}

// // This gets called on every request
// This gets called on every request
// export async function getRegistrationServerSideProps(
// context: GetServerSidePropsContext,
// ) {
Expand Down Expand Up @@ -90,7 +108,7 @@ export function useRegistrationFlow(): RegistrationFlow | null | void {
// }),
// )
// }
//

// function replaceUndefinedWithNull(obj: unknown): unknown {
// if (Array.isArray(obj)) {
// return obj.map(replaceUndefinedWithNull)
Expand All @@ -100,10 +118,10 @@ export function useRegistrationFlow(): RegistrationFlow | null | void {
// if (value === undefined) {
// delete (obj as Record<string, unknown>)[key]
// } else {
// (obj as Record<string, unknown>)[key] = replaceUndefinedWithNull(value)
// ;(obj as Record<string, unknown>)[key] = replaceUndefinedWithNull(value)
// }
// })
// return obj
// }
// return obj
// }
// }

0 comments on commit 04b3fed

Please sign in to comment.