-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add nextjs example and supporting libraries #240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but this triggered me during the presentation 😉
🤣 |
This comment was marked as outdated.
This comment was marked as outdated.
I'm stuck trying to create the |
@@ -0,0 +1,3 @@ | |||
import { OryCardContent } from "@ory/elements-react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be `OryCardLayout
import { OryCardContent } from "@ory/elements-react" | |
import { OryCardLayout } from "@ory/elements-react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do export that file, it should be
This should actually be
import { OryCardContent } from "@ory/elements-react" | |
import { OryCardLayout } from "@ory/elements-react/theme" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonas-jonas it's now:
// app/auth/layout.tsx
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { DefaultCardLayout } from "@ory/elements-react/theme"
export default DefaultCardLayout
|
||
export function DefaultCardLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<main className="p-4 pb-8 flex items-center justify-center flex-col gap-8 min-h-screen"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem kinda is that we have the card element, but no backdrop element, so the card just is on the top left of the screen. We should add a layout component or background component. Not sure where to put it, so i put it here. But it's kinda weird because we don't override it anywhere, we just import it (see nextjs app router example app)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. IMO, if you use Ory Elements, you should need to decide where to put the elements on the page, so it's up to the consumer to implement this. I guess it doesn't hurt to export this, but it's a really optional element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed and this is how it's done now.
This comment was marked as outdated.
This comment was marked as outdated.
079ab44
to
8c3bc44
Compare
8c3bc44
to
7f3319b
Compare
|
||
export function DefaultCardLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<main className="p-4 pb-8 flex items-center justify-center flex-col gap-8 min-h-screen"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. IMO, if you use Ory Elements, you should need to decide where to put the elements on the page, so it's up to the consumer to implement this. I guess it doesn't hurt to export this, but it's a really optional element.
packages/nextjs/src/pages/utils.ts
Outdated
export function useSearchParams() { | ||
const router = useRouter() | ||
return toSearchParams(router.query) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this exported in the package? If so, this will lead to it showing up in code completion if you have this package installed, which is not great, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0
"use client"
export { useRegistrationFlow } from "./registration"
export { oryPageRouterConfig } from "./config"
is exported in utils/index.js
@@ -0,0 +1,3 @@ | |||
import { OryCardContent } from "@ory/elements-react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do export that file, it should be
This should actually be
import { OryCardContent } from "@ory/elements-react" | |
import { OryCardLayout } from "@ory/elements-react/theme" |
Makefile
Outdated
build: | ||
npm run build | ||
|
||
dev: | ||
npm run build | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've adjusted the scripts to now use the nx commands, which I always had to lookup in the GitHub ci config.
@@ -0,0 +1,49 @@ | |||
This is a [Next.js](https://nextjs.org) project bootstrapped with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a proper README.
body { | ||
color: var(--foreground); | ||
background: var(--background); | ||
font-family: Arial, Helvetica, sans-serif; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use Inter in the designs, so the examples should, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is included in the default example. We should probably add an api route that verifies the cookie here?
}) | ||
|
||
xit("should use window.location.origin if VERCEL_URL is not provided", () => { | ||
// Not sure if this works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we need to check to make sure this works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow be able to modify window.location.origin which I have not been able to get working in this test
packages/nextjs/src/utils/config.ts
Outdated
import { OryConfig } from "../types" | ||
import { isProduction } from "./sdk" | ||
|
||
export function enhanceConfig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function enhanceConfig( | |
export function enhanceOryConfig( |
And it needs docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
test("understands public suffix list", () => { | ||
expect( | ||
guessCookieDomain( | ||
"https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, where does this come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An LLM, maybe.
new URL(selfUrl).toString().replace(/\/$/, ""), | ||
) | ||
} | ||
export function rewriteJsonResponse<T extends object>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs tests. Seems like a pretty complicated function, maybe some docs/explanations would be good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have several tests for this in describe("rewriteJsonResponse", () => {
I added docs
tsconfig.base.json
Outdated
@@ -9,6 +9,7 @@ | |||
"skipLibCheck": true, | |||
"baseUrl": ".", | |||
"paths": { | |||
"@ory/nextjs": ["packages/nextjs/src/index.ts"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this is needed with npm workspaces, why did you add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
53178c6
to
254f36e
Compare
254f36e
to
4311b66
Compare
Closes ory/integrations#61
BREAKING CHANGES: This patch changes the options structure for
useSesssion
.