How to change the default API path for `/me` (and who called it)

Hi,

I’m trying a simple authentication with a different route path, in nextjs

my layout.ts

import { UserProvider } from "@auth0/nextjs-auth0/client";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <UserProvider>
        <body className={inter.className}>{children}</body>
      </UserProvider>
    </html>
  );
}

page.ts

import { getSession } from "@auth0/nextjs-auth0";

export default async function Home() {
  const { user } = await getSession();
  console.log(user);

  return (
    <main className="flex min-h-screen flex-col items-center justify-between p-24">
      <a href="/auth/api/login">Login</a>
      {user && (
        <div>
          <img src={user.picture} alt={user.name} />
          <h2>{user.name}</h2>
          <p>{user.email}</p>
        </div>
      )}
    </main>
  );
}

.env.local

AUTH0_SECRET=
AUTH0_BASE_URL='http://localhost:3000'
AUTH0_ISSUER_BASE_URL=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=''
AUTH0_CALLBACK='/auth/api/callback'

so, instead use default /api/auth/... im using /auth/api/.... everything is working fine. except that when I’ loading the page, there’s some calling to the default me route and I’m not sure where it is coming from

Hi @lzh

Welcome to the Auth0 Community!

Thank you for posting your question. I’m not a Next.js expert, but I’ve done some research and found a similar issue in other thread → Http://localhost:3000/api/auth/me returns 404 in Console - #8 by wisenickel5, which points to the code snippet from the NextJS Auth0 readme.md. Let me know if this solves your issue.

Thanks
Dawid

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.