Skip to content

Commit 9eefbe6

Browse files
committed
fix: add type cast for csrf-armor NextRequest compatibility
1 parent 62ddb73 commit 9eefbe6

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

examples/nextjs-app-router-custom-components/middleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const oryPathPrefixes = [
2929
]
3030

3131
export async function middleware(request: NextRequest) {
32-
const oryResponse = await oryMiddleware(request)
32+
// Type cast needed due to Next.js version differences between packages
33+
const oryResponse = await oryMiddleware(
34+
request as Parameters<typeof oryMiddleware>[0],
35+
)
3336

3437
const isOryPath = oryPathPrefixes.some((prefix) =>
3538
request.nextUrl.pathname.startsWith(prefix),
@@ -39,7 +42,10 @@ export async function middleware(request: NextRequest) {
3942
}
4043

4144
const response = NextResponse.next()
42-
const result = await csrfProtect(request, response)
45+
const result = await csrfProtect(
46+
request as Parameters<typeof csrfProtect>[0],
47+
response as Parameters<typeof csrfProtect>[1],
48+
)
4349
if (!result.success) {
4450
return NextResponse.json(
4551
{ error: "CSRF validation failed" },

examples/nextjs-app-router/middleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const oryPathPrefixes = [
2929
]
3030

3131
export async function middleware(request: NextRequest) {
32-
const oryResponse = await oryMiddleware(request)
32+
// Type cast needed due to Next.js version differences between packages
33+
const oryResponse = await oryMiddleware(
34+
request as Parameters<typeof oryMiddleware>[0],
35+
)
3336

3437
const isOryPath = oryPathPrefixes.some((prefix) =>
3538
request.nextUrl.pathname.startsWith(prefix),
@@ -39,7 +42,10 @@ export async function middleware(request: NextRequest) {
3942
}
4043

4144
const response = NextResponse.next()
42-
const result = await csrfProtect(request, response)
45+
const result = await csrfProtect(
46+
request as Parameters<typeof csrfProtect>[0],
47+
response as Parameters<typeof csrfProtect>[1],
48+
)
4349
if (!result.success) {
4450
return NextResponse.json(
4551
{ error: "CSRF validation failed" },

examples/nextjs-pages-router/middleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const oryPathPrefixes = [
2929
]
3030

3131
export async function middleware(request: NextRequest) {
32-
const oryResponse = await oryMiddleware(request)
32+
// Type cast needed due to Next.js version differences between packages
33+
const oryResponse = await oryMiddleware(
34+
request as Parameters<typeof oryMiddleware>[0],
35+
)
3336

3437
const isOryPath = oryPathPrefixes.some((prefix) =>
3538
request.nextUrl.pathname.startsWith(prefix),
@@ -39,7 +42,10 @@ export async function middleware(request: NextRequest) {
3942
}
4043

4144
const response = NextResponse.next()
42-
const result = await csrfProtect(request, response)
45+
const result = await csrfProtect(
46+
request as Parameters<typeof csrfProtect>[0],
47+
response as Parameters<typeof csrfProtect>[1],
48+
)
4349
if (!result.success) {
4450
return NextResponse.json(
4551
{ error: "CSRF validation failed" },

0 commit comments

Comments
 (0)