-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from kubetail-org/next15
Adds support for Next 15
- Loading branch information
Showing
108 changed files
with
2,408 additions
and
85 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
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,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
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,26 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, install dependencies: | ||
|
||
```bash | ||
npm install | ||
# or | ||
pnpm install | ||
# or | ||
yarn install | ||
``` | ||
|
||
Next, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
pnpm dev | ||
# or | ||
yarn dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
5 changes: 5 additions & 0 deletions
5
examples/next15-approuter-html-submission/app/form-handler/route.ts
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,5 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST() { | ||
return NextResponse.json({ status: 'success' }); | ||
} |
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,19 @@ | ||
import { Metadata } from 'next'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'edge-csrf html form submission example', | ||
}; | ||
|
||
export default function Layout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} |
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,57 @@ | ||
import { headers } from 'next/headers'; | ||
|
||
import '../styles/globals.css'; | ||
|
||
export default async function Page() { | ||
const headersList = await headers(); | ||
const csrfToken = headersList.get('X-CSRF-Token') || 'missing'; | ||
|
||
return ( | ||
<> | ||
<p> | ||
CSRF token value: | ||
{csrfToken} | ||
</p> | ||
<h2>HTML Form Submission Example:</h2> | ||
<form action="/form-handler" method="post"> | ||
<legend>Form without CSRF (should fail):</legend> | ||
<input type="text" name="input1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<br /> | ||
<form action="/form-handler" method="post"> | ||
<legend>Form with incorrect CSRF (should fail):</legend> | ||
<input type="hidden" name="csrf_token" value="notvalid" /> | ||
<input type="text" name="input1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<br /> | ||
<form action="/form-handler" method="post"> | ||
<legend>Form with CSRF (should succeed):</legend> | ||
<input type="hidden" name="csrf_token" value={csrfToken} /> | ||
<input type="text" name="input1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<h2>HTML File Upload Example:</h2> | ||
<form action="/form-handler" method="post" encType="multipart/form-data"> | ||
<legend>Form without CSRF (should fail):</legend> | ||
<input type="file" name="file1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<br /> | ||
<form action="/form-handler" method="post" encType="multipart/form-data"> | ||
<legend>Form with incorrect CSRF (should fail):</legend> | ||
<input type="hidden" name="csrf_token" value="notvalid" /> | ||
<input type="file" name="file1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<br /> | ||
<form action="/form-handler" method="post" encType="multipart/form-data"> | ||
<legend>Form with CSRF (should succeed):</legend> | ||
<input type="hidden" name="csrf_token" value={csrfToken} /> | ||
<input type="file" name="file1" /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</> | ||
); | ||
} |
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,10 @@ | ||
import { createCsrfMiddleware } from '@edge-csrf/nextjs'; | ||
|
||
// initalize csrf protection middleware | ||
const csrfMiddleware = createCsrfMiddleware({ | ||
cookie: { | ||
secure: process.env.NODE_ENV === 'production', | ||
}, | ||
}); | ||
|
||
export const middleware = csrfMiddleware; |
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,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. |
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,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
|
||
module.exports = nextConfig; |
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,23 @@ | ||
{ | ||
"name": "edge-csrf-example", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@edge-csrf/nextjs": "^2.0.0", | ||
"@types/node": "^20.8.9", | ||
"@types/react": "^18.2.33", | ||
"@types/react-dom": "^18.2.14", | ||
"eslint": "^8.52.0", | ||
"eslint-config-next": "^15.0.0", | ||
"next": "^15.0.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions
26
examples/next15-approuter-html-submission/styles/globals.css
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,26 @@ | ||
html, | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, | ||
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; | ||
} | ||
|
||
a { | ||
color: blue; | ||
text-decoration: underline; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
html { | ||
color-scheme: dark; | ||
} | ||
body { | ||
color: white; | ||
background: black; | ||
} | ||
} |
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,36 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"target": "ES2017", | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx", | ||
".next/types/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/next15-approuter-js-submission-dynamic/.eslintrc.json
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,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
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,26 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, install dependencies: | ||
|
||
```bash | ||
npm install | ||
# or | ||
pnpm install | ||
# or | ||
yarn install | ||
``` | ||
|
||
Next, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
pnpm dev | ||
# or | ||
yarn dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
5 changes: 5 additions & 0 deletions
5
examples/next15-approuter-js-submission-dynamic/app/form-handler/route.ts
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,5 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST() { | ||
return NextResponse.json({ status: 'success' }); | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/next15-approuter-js-submission-dynamic/app/layout.tsx
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,28 @@ | ||
import { Metadata } from 'next'; | ||
import { headers } from 'next/headers'; | ||
|
||
export async function generateMetadata(): Promise<Metadata> { | ||
const headersList = await headers(); | ||
const csrfToken = headersList.get('X-CSRF-Token') || 'missing'; | ||
|
||
return { | ||
title: 'edge-csrf example', | ||
other: { | ||
'x-csrf-token': csrfToken, | ||
}, | ||
}; | ||
} | ||
|
||
export default function Layout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} |
Oops, something went wrong.