Auth0 provides a routing setup kit for the traditional Pages Router. Is there a way to use Auth0 routes on the new App Router?
- App Router (Next.js): https://nextjs.org/docs/app
- Add the dynamic API route (Auth0): https://auth0.com/docs/quickstart/webapp/nextjs/01-login#add-the-dynamic-api-route
Here is an example code by Auth0 doc:
// pages/api/auth/[...auth0].js
import { handleAuth } from '@auth0/nextjs-auth0';
export default handleAuth();
If you put the code at src/app/api/auth/[...auth0]/route.js
, which is a way of App Router, Next.js shows following errors:
- error Detected default export in '/…/app/api/auth/[...auth0]/route.ts'. Export a named export for each HTTP method instead.
- error No HTTP methods exported in '/…/app/api/auth/[...auth0]/route.ts'. Export a named export for each HTTP method.
Because the App Router requires a different interface from the express.js way. Here is an example for the new way:
// src/app/api/auth/[...auth0]/route.ts
import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json({ message: "Hello, World!" });
}
I'm looking for an escape hatch that works until they officially support the App Router.