Is it possible to utilize Auth0 routes on the new App Router instead of the traditional Pages Router setup kit provided by Auth0?
- Learn more about App Router (Next.js) here: https://nextjs.org/docs/app
- Check out how to add the dynamic API route with Auth0 here: https://auth0.com/docs/quickstart/webapp/nextjs/01-login#add-the-dynamic-api-route
An example code snippet from the Auth0 documentation:
// pages/api/auth/[...auth0].js
import { handleAuth } from '@auth0/nextjs-auth0';
export default handleAuth();
When trying to place the code at
src/app/api/auth/[...auth0]/route.js
for the App Router, Next.js throws the 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.
This is because the App Router requires a different interface compared to the express.js way. Here is an example of the new approach:
// src/app/api/auth/[...auth0]/route.ts
import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json({ message: "Hello, World!" });
}
I am currently seeking a workaround that functions effectively until official support for the App Router is available.