Skip to content

Commit 728f500

Browse files
authored
1 parent 884209f commit 728f500

File tree

27 files changed

+851
-263
lines changed

27 files changed

+851
-263
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
12
<a href="https://arcjet.com" target="_arcjet-home">
23
<picture>
34
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
@@ -76,6 +77,19 @@ server](https://arcjet.com/discord).
7677
- Client-side validation: [Zod](https://zod.dev/)
7778
- Security: [Arcjet](https://arcjet.com/)
7879

80+
## Contributing
81+
82+
All development for Arcjet examples is done in the
83+
[`arcjet/examples` repository](https://github.com/arcjet/examples).
84+
85+
You are welcome to open an issue here or in
86+
[`arcjet/examples`](https://github.com/arcjet/examples/issues) directly.
87+
However, please direct all pull requests to
88+
[`arcjet/examples`](https://github.com/arcjet/examples/pulls). Take a look at
89+
our
90+
[contributing guide](https://github.com/arcjet/examples/blob/main/CONTRIBUTING.md)
91+
for more information.
92+
7993
[vercel_deploy]: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Farcjet%2Fexample-nextjs&project-name=arcjet-example&repository-name=arcjet-example&developer-id=oac_1GEcKBuKBilVnjToj1QUwdb8&demo-title=Arcjet%20Example%20&demo-description=Example%20rate%20limiting%2C%20bot%20protection%2C%20email%20verification%20%26%20form%20protection.&demo-url=https%3A%2F%2Fgithub.com%2Farcjet%2Fexample-nextjs&demo-image=https%3A%2F%2Fapp.arcjet.com%2Fimg%2Fexample-apps%2Fvercel%2Fdemo-image.jpg&integration-ids=oac_1GEcKBuKBilVnjToj1QUwdb8&external-id=arcjet-js-example◊
8094
[vercel_button]: https://vercel.com/button
8195
[netlify_deploy]: https://app.netlify.com/start/deploy?repository=https://github.com/arcjet/example-nextjs

app/api/auth/[...nextauth]/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// This is Auth.js 5, the successor to NextAuth 4
2-
import arcjet, { detectBot, shield, slidingWindow } from "@/lib/arcjet";
3-
import { handlers } from "@/lib/auth";
4-
import ip from "@arcjet/ip";
2+
53
import { isDevelopment } from "@arcjet/env";
4+
import ip from "@arcjet/ip";
65
import { NextRequest, NextResponse } from "next/server";
6+
import arcjet, { detectBot, shield, slidingWindow } from "@/lib/arcjet";
7+
import { handlers } from "@/lib/auth";
78

89
// Add rules to the base Arcjet instance outside of the handler function
910
const aj = arcjet

app/attack/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import VisitDashboard from "@/components/compositions/VisitDashboard";
2-
import { WhatNext } from "@/components/compositions/WhatNext";
31
import type { Metadata } from "next";
42
import { headers } from "next/headers";
53
import Link from "next/link";
4+
import VisitDashboard from "@/components/compositions/VisitDashboard";
5+
import { WhatNext } from "@/components/compositions/WhatNext";
66

77
export const metadata: Metadata = {
88
title: "Attack protection example",

app/attack/test/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import arcjet, { shield } from "@/lib/arcjet";
21
import { isDevelopment } from "@arcjet/env";
32
import ip from "@arcjet/ip";
4-
import { NextRequest, NextResponse } from "next/server";
3+
import { type NextRequest, NextResponse } from "next/server";
4+
import arcjet, { shield } from "@/lib/arcjet";
55

66
// Opt out of caching
77
export const dynamic = "force-dynamic";
@@ -32,7 +32,7 @@ export async function GET(req: NextRequest) {
3232
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
3333
} else if (decision.isErrored()) {
3434
console.error("Arcjet error:", decision.reason);
35-
if (decision.reason.message == "[unauthenticated] invalid key") {
35+
if (decision.reason.message === "[unauthenticated] invalid key") {
3636
return NextResponse.json(
3737
{
3838
message:
@@ -42,7 +42,7 @@ export async function GET(req: NextRequest) {
4242
);
4343
} else {
4444
return NextResponse.json(
45-
{ v: "Internal server error: " + decision.reason.message },
45+
{ v: `Internal server error: ${decision.reason.message}` },
4646
{ status: 500 },
4747
);
4848
}

app/bots/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import VisitDashboard from "@/components/compositions/VisitDashboard";
2-
import { WhatNext } from "@/components/compositions/WhatNext";
31
import type { Metadata } from "next";
42
import { headers } from "next/headers";
53
import Link from "next/link";
4+
import VisitDashboard from "@/components/compositions/VisitDashboard";
5+
import { WhatNext } from "@/components/compositions/WhatNext";
66

77
export const metadata: Metadata = {
88
title: "Bot protection example",

app/bots/test/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import arcjet, { detectBot, fixedWindow } from "@/lib/arcjet";
21
import { isDevelopment } from "@arcjet/env";
32
import ip from "@arcjet/ip";
4-
import { NextRequest, NextResponse } from "next/server";
3+
import { type NextRequest, NextResponse } from "next/server";
4+
import arcjet, { detectBot, fixedWindow } from "@/lib/arcjet";
55

66
// Opt out of caching
77
export const dynamic = "force-dynamic";
@@ -37,7 +37,7 @@ export async function GET(req: NextRequest) {
3737
console.log("Arcjet decision: ", decision);
3838

3939
// Use the IP analysis to customize the response based on the country
40-
if (decision.ip.hasCountry() && decision.ip.country == "JP") {
40+
if (decision.ip.hasCountry() && decision.ip.country === "JP") {
4141
return NextResponse.json({ message: "Konnichiwa!" });
4242
}
4343

@@ -54,7 +54,7 @@ export async function GET(req: NextRequest) {
5454
return NextResponse.json({ error: "Too many requests" }, { status: 429 });
5555
} else if (decision.isErrored()) {
5656
console.error("Arcjet error:", decision.reason);
57-
if (decision.reason.message == "[unauthenticated] invalid key") {
57+
if (decision.reason.message === "[unauthenticated] invalid key") {
5858
return NextResponse.json(
5959
{
6060
message:
@@ -64,7 +64,7 @@ export async function GET(req: NextRequest) {
6464
);
6565
} else {
6666
return NextResponse.json(
67-
{ message: "Internal server error: " + decision.reason.message },
67+
{ message: `Internal server error: ${decision.reason.message}` },
6868
{ status: 500 },
6969
);
7070
}

app/layout.tsx

Lines changed: 89 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Metadata } from "next";
2-
import Script from "next/script";
3-
import Link from "next/link";
42
import Image from "next/image";
5-
6-
import { siteConfig } from "@/config/site";
3+
import Link from "next/link";
4+
import Script from "next/script";
5+
import LogoDark from "@/assets/logo-dark.svg";
76

87
import LogoLight from "@/assets/logo-light.svg";
9-
import LogoDark from "@/assets/logo-dark.svg";
8+
import { siteConfig } from "@/config/site";
109

1110
import "@/styles/styles.css";
12-
import { IconMenu } from "@/components/icons/Menu";
1311
import { IconCancel } from "@/components/icons/Cancel";
14-
import { PopoverTarget } from "@/components/PopoverTarget";
12+
import { IconMenu } from "@/components/icons/Menu";
1513
import { NavLink } from "@/components/NavLink";
14+
import { PopoverTarget } from "@/components/PopoverTarget";
1615

1716
export const metadata: Metadata = {
1817
title: {
@@ -42,91 +41,89 @@ type Props = {
4241

4342
export default function RootLayout({ children }: Props) {
4443
return (
45-
<>
46-
<html lang="en" suppressHydrationWarning>
47-
<head>
48-
<Script
49-
defer
50-
src="https://plausible.io/js/script.js"
51-
data-domain="arcjet.com"
52-
/>
53-
</head>
54-
<body className="layout">
55-
<header className="header">
56-
<Link href="/">
57-
<Image
58-
src={LogoLight}
59-
alt="Arcjet Example app"
60-
height={30}
61-
width={310}
62-
className="light"
63-
/>
64-
<Image
65-
src={LogoDark}
66-
alt="Arcjet Example app"
67-
height={30}
68-
width={310}
69-
className="dark"
70-
/>
71-
</Link>
72-
<div className="header-end">
73-
<button
74-
className="hamburger-menu"
75-
popoverTarget="navigation"
76-
popoverTargetAction="toggle"
77-
>
78-
<IconMenu classes={["hamburger-menu-menu-icon"]} />
79-
<IconCancel classes={["hamburger-menu-cancel-icon"]} />
80-
</button>
81-
<PopoverTarget id="navigation" closeAtWidthPx={1024}>
82-
<ul className="navigation-links">
83-
<li>
84-
<NavLink className="navigation-link" href="/signup">
85-
Signup form protection
86-
</NavLink>
87-
</li>
88-
<li>
89-
<NavLink className="navigation-link" href="/bots">
90-
Bot protection
91-
</NavLink>
92-
</li>
93-
<li>
94-
<NavLink className="navigation-link" href="/rate-limiting">
95-
Rate limiting
96-
</NavLink>
97-
</li>
98-
<li>
99-
<NavLink className="navigation-link" href="/attack">
100-
Attack protection
101-
</NavLink>
102-
</li>
103-
<li>
104-
<NavLink className="navigation-link" href="/sensitive-info">
105-
Sensitive info
106-
</NavLink>
107-
</li>
108-
</ul>
109-
</PopoverTarget>
110-
<a
111-
className="navigation-icon"
112-
href="https://github.com/arcjet/example-nextjs"
113-
target="_blank"
114-
rel="noreferrer"
44+
<html lang="en" suppressHydrationWarning>
45+
<head>
46+
<Script
47+
defer
48+
src="https://plausible.io/js/script.js"
49+
data-domain="arcjet.com"
50+
/>
51+
</head>
52+
<body className="layout">
53+
<header className="header">
54+
<Link href="/">
55+
<Image
56+
src={LogoLight}
57+
alt="Arcjet Example app"
58+
height={30}
59+
width={310}
60+
className="light"
61+
/>
62+
<Image
63+
src={LogoDark}
64+
alt="Arcjet Example app"
65+
height={30}
66+
width={310}
67+
className="dark"
68+
/>
69+
</Link>
70+
<div className="header-end">
71+
<button
72+
className="hamburger-menu"
73+
popoverTarget="navigation"
74+
popoverTargetAction="toggle"
75+
>
76+
<IconMenu classes={["hamburger-menu-menu-icon"]} />
77+
<IconCancel classes={["hamburger-menu-cancel-icon"]} />
78+
</button>
79+
<PopoverTarget id="navigation" closeAtWidthPx={1024}>
80+
<ul className="navigation-links">
81+
<li>
82+
<NavLink className="navigation-link" href="/signup">
83+
Signup form protection
84+
</NavLink>
85+
</li>
86+
<li>
87+
<NavLink className="navigation-link" href="/bots">
88+
Bot protection
89+
</NavLink>
90+
</li>
91+
<li>
92+
<NavLink className="navigation-link" href="/rate-limiting">
93+
Rate limiting
94+
</NavLink>
95+
</li>
96+
<li>
97+
<NavLink className="navigation-link" href="/attack">
98+
Attack protection
99+
</NavLink>
100+
</li>
101+
<li>
102+
<NavLink className="navigation-link" href="/sensitive-info">
103+
Sensitive info
104+
</NavLink>
105+
</li>
106+
</ul>
107+
</PopoverTarget>
108+
<a
109+
className="navigation-icon"
110+
href="https://github.com/arcjet/example-nextjs"
111+
target="_blank"
112+
rel="noreferrer"
113+
>
114+
<svg
115+
aria-label="GitHub"
116+
role="img"
117+
fill="currentColor"
118+
viewBox="0 0 438.549 438.549"
115119
>
116-
<svg
117-
aria-label="GitHub"
118-
role="img"
119-
fill="currentColor"
120-
viewBox="0 0 438.549 438.549"
121-
>
122-
<path d="M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"></path>
123-
</svg>
124-
</a>
125-
</div>
126-
</header>
127-
{children}
128-
</body>
129-
</html>
130-
</>
120+
<path d="M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"></path>
121+
</svg>
122+
</a>
123+
</div>
124+
</header>
125+
{children}
126+
</body>
127+
</html>
131128
);
132129
}

app/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { WhatNext } from "@/components/compositions/WhatNext";
21
import Link from "next/link";
2+
import { WhatNext } from "@/components/compositions/WhatNext";
33

44
export default function IndexPage() {
55
const siteKey = process.env.ARCJET_SITE ? process.env.ARCJET_SITE : null;
@@ -21,7 +21,7 @@ export default function IndexPage() {
2121
<Link
2222
href="https://github.com/arcjet/example-nextjs"
2323
target="_blank"
24-
rel="noreferrer"
24+
rel="noopener noreferrer"
2525
className="link"
2626
>
2727
on GitHub
@@ -62,13 +62,15 @@ export default function IndexPage() {
6262
href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Farcjet%2Fexample-nextjs&project-name=arcjet-example&repository-name=arcjet-example&developer-id=oac_1GEcKBuKBilVnjToj1QUwdb8&demo-title=Arcjet%20Example%20&demo-description=Example%20rate%20limiting%2C%20bot%20protection%2C%20email%20verification%20%26%20form%20protection.&demo-url=https%3A%2F%2Fgithub.com%2Farcjet%2Fexample-nextjs&demo-image=https%3A%2F%2Fapp.arcjet.com%2Fimg%2Fexample-apps%2Fvercel%2Fdemo-image.jpg&integration-ids=oac_1GEcKBuKBilVnjToj1QUwdb8&external-id=arcjet-js-example"
6363
title="Deploy with Vercel"
6464
target="_blank"
65+
rel="noopener noreferrer"
6566
>
6667
<img src="https://vercel.com/button" alt="Deploy with Vercel" />
6768
</a>
6869
<a
6970
href="https://app.netlify.com/start/deploy?repository=https://github.com/arcjet/example-nextjs"
7071
title="Deploy to Netlify"
7172
target="_blank"
73+
rel="noopener noreferrer"
7274
>
7375
<img
7476
src="https://www.netlify.com/img/deploy/button.svg"

app/rate-limiting/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { Metadata } from "next";
2+
import Link from "next/link";
3+
import { WhatNext } from "@/components/compositions/WhatNext";
14
import { RLForm } from "@/components/RLForm";
25
import { SignIn } from "@/components/SignIn";
36
import { SignOut } from "@/components/SignOut";
4-
import { WhatNext } from "@/components/compositions/WhatNext";
57
import { auth } from "@/lib/auth";
6-
import type { Metadata } from "next";
7-
import Link from "next/link";
88

99
export const metadata: Metadata = {
1010
title: "Rate limiting example",

0 commit comments

Comments
 (0)