Catch all routes
Course: Next Auth - chapter 4
If you want to add a single route handler for
/api/auth/user/api/auth/random/api/auth/123/api/auth/...
You can create a catch all route
- Create a simple next.js app
npx create-next-app@latest- Create
app/api/auth/[...nextauth]/route.ts
import { NextRequest, NextResponse } from "next/server"
export function GET(req: NextRequest) { return NextResponse.json({ message: "Handler" })}- Try going to a few endpoints
http://localhost:3000/api/auth/signinhttp://localhost:3000/api/auth/123http://localhost:3000/api/auth/random/random2- Try logging the sub-route you’re at
import { NextRequest, NextResponse } from "next/server"
export function GET(req: NextRequest, { params }: { params: { nextauth: string[] } }) { console.log(params.nextauth[0]) return NextResponse.json({ message: "Handler" })}