Skip to content

Commit ecd5bfd

Browse files
aeneasrjonas-jonas
andauthored
feat: add page and app router examples (#307)
Co-authored-by: Jonas Hungershausen <jonas.hungershausen@ory.sh>
1 parent cbfeceb commit ecd5bfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2812
-127
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ export PATH := .bin:${PATH}
66
.PHONY: install
77
install:
88
npm install
9+
npx playwright install --with-deps
910

11+
.PHONY: test
1012
test:
1113
npm run test
1214

15+
.PHONY: build
16+
build:
17+
npx nx run-many --target=build --all
18+
npx nx run-many --all --target=build-storybook -- --stats-json
19+
20+
.PHONY: dev
21+
dev:
22+
npx nx run-many --target=dev --all
23+
1324
test-containerized:
1425
# https://github.com/microsoft/playwright/issues/26482
1526
# For unsupported distros, use the `test-containerized` target instead of `test`
1627
sh -c ./playwright-docker.sh
1728

18-
1929
PRETTIER_VERSION=$(shell cat package.json | jq -r '.devDependencies["prettier"] // .dependencies["prettier"]')
2030

2131
format: .bin/ory
2232
.bin/ory dev headers copyright --type=open-source
2333
@echo "Prettier Version: $(PRETTIER_VERSION)"
2434
npx prettier@$$PRETTIER_VERSION --write .
2535

26-
2736
licenses: .bin/licenses node_modules # checks open-source licenses
2837
.bin/licenses
2938

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ const config = tseslint.config([
106106
"no-extra-semi": "off",
107107
},
108108
},
109+
{
110+
files: [
111+
"examples/nextjs-app-router/**/*.ts",
112+
"examples/nextjs-app-router/**/*.tsx",
113+
],
114+
languageOptions: {
115+
parserOptions: {
116+
project: ["./examples/nextjs-app-router/tsconfig.json"],
117+
},
118+
},
119+
},
109120
{
110121
name: "elements-react",
111122
files: ["packages/elements-react/**"],

examples/nextjs-app-router/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_ORY_SDK_URL=https://playground.projects.oryapis.com
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
This is a simple example application using @ory/elements-react & Next.js app
2+
router.
3+
4+
## Getting started
5+
6+
1. Sign up for an account at https://console.ory.sh
7+
2. Create a new or use an existing project
8+
3. Go to https://console.ory.sh/projects/current/settings and copy the **API
9+
endpoints** URL
10+
4. Set the `NEXT_PUBLIC_ORY_SDK_URL` to your project's **API endpoints** URL
11+
5. Run `npm install`
12+
6. Run `npm run dev` and open navigate to http://localhost:3000
13+
14+
<!-- prettier-ignore-start -->
15+
> [!WARNING]
16+
> For convinience Ory provides a default "playground" project, that
17+
> can be used to interact with Ory's APIs. It is a public project, that can be
18+
> used by anyone and data can be deleted at any time. Make sure to use a
19+
> dedicated project.
20+
<!-- prettier-ignore-end -->
21+
22+
## Features
23+
24+
- All self-service user flows Ory supports
25+
- [Login](http://localhost:3000/auth/login)
26+
- [Registration](http://localhost:3000/auth/registration)
27+
- [Recovery](http://localhost:3000/auth/recovery)
28+
- [Verification](http://localhost:3000/auth/verification)
29+
- [Settings](http://localhost:3000/settings)
30+
- User Logout
31+
32+
## Project structure
33+
34+
The project files reside in the `app/` directory:
35+
36+
- `app/auth` - contains the page files for the user auth flows
37+
- `app/settings` - contaisn the page file for the settings flow
38+
- `app` - contains the root page file and layout.
39+
40+
## Need help?
41+
42+
If you have any issues using this examples, or Ory's products, don't hesitate to
43+
reach out via the [Ory Community Slack](https://slack.ory.sh).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright © 2024 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { DefaultCardLayout } from "@ory/elements-react/theme"
5+
import "@ory/elements-react/theme/styles.css"
6+
7+
export default DefaultCardLayout
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright © 2024 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Login } from "@ory/elements-react/theme"
5+
import { enhanceOryConfig } from "@ory/nextjs"
6+
import { getLoginFlow, OryPageParams } from "@ory/nextjs/app"
7+
8+
import config from "@/ory.config"
9+
10+
export default async function LoginPage(props: OryPageParams) {
11+
const flow = await getLoginFlow(props.searchParams)
12+
13+
if (!flow) {
14+
return null
15+
}
16+
17+
return (
18+
<Login
19+
flow={flow}
20+
config={enhanceOryConfig(config)}
21+
components={{
22+
Card: {},
23+
}}
24+
/>
25+
)
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2024 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Recovery } from "@ory/elements-react/theme"
5+
import { enhanceOryConfig } from "@ory/nextjs"
6+
import { getRecoveryFlow, OryPageParams } from "@ory/nextjs/app"
7+
8+
import CustomCardHeader from "@/components/custom-card-header"
9+
import config from "@/ory.config"
10+
11+
export default async function RecoveryPage(props: OryPageParams) {
12+
const flow = await getRecoveryFlow(props.searchParams)
13+
14+
if (!flow) {
15+
return null
16+
}
17+
18+
return (
19+
<Recovery
20+
flow={flow}
21+
config={enhanceOryConfig(config)}
22+
components={{
23+
Card: {
24+
Header: CustomCardHeader,
25+
},
26+
}}
27+
/>
28+
)
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright © 2024 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Registration } from "@ory/elements-react/theme"
5+
import { enhanceOryConfig } from "@ory/nextjs"
6+
import { getRegistrationFlow, OryPageParams } from "@ory/nextjs/app"
7+
8+
import config from "@/ory.config"
9+
10+
export default async function RegistrationPage(props: OryPageParams) {
11+
const flow = await getRegistrationFlow(props.searchParams)
12+
13+
if (!flow) {
14+
return null
15+
}
16+
17+
return (
18+
<Registration
19+
flow={flow}
20+
config={enhanceOryConfig(config)}
21+
components={{
22+
Card: {},
23+
}}
24+
/>
25+
)
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2024 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Verification } from "@ory/elements-react/theme"
5+
import { enhanceOryConfig } from "@ory/nextjs"
6+
import { getVerificationFlow, OryPageParams } from "@ory/nextjs/app"
7+
8+
import CustomCardHeader from "@/components/custom-card-header"
9+
import config from "@/ory.config"
10+
11+
export default async function VerificationPage(props: OryPageParams) {
12+
const flow = await getVerificationFlow(props.searchParams)
13+
14+
if (!flow) {
15+
return null
16+
}
17+
18+
return (
19+
<Verification
20+
flow={flow}
21+
config={enhanceOryConfig(config)}
22+
components={{
23+
Card: {
24+
Header: CustomCardHeader,
25+
},
26+
}}
27+
/>
28+
)
29+
}

0 commit comments

Comments
 (0)