Next.js Discord

Discord Forum

Next auth issues with next js 15

Unanswered
Havana posted this in #help-forum
Open in Discord
Avatar
HavanaOP
Error: Route "/profile" used headers().get('x-forwarded-proto'). headers() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
Image

18 Replies

Avatar
HavanaOP
have installed all the things via codemod
getting error over here
[ Server ] Error: Route "/dashboard" used headers().get('x-forwarded-proto'). headers() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
I have not made any headers() calls in my app
but the internal next auth is making one it says ?
Avatar
show the dashboard code
Avatar
HavanaOP
import { productList } from "@/app/(user)/products/productList";
import connectDb from "@/db/connectDb";
import { Customers, ICustomer } from "@/db/customers";
import { getMostSoldProduct } from "@/utils/mostSold";
import { auth } from "@/auth";
import { NotAuth } from "./NotAuth";
import { calcProfit } from "@/utils/profitCalc";
import DashboardClient from "./dashboardClient";
import { getCachedCustomers } from "@/utils/fetchCusotmers";
import StaffMotivation from "./StaffMotivation";
import UserModel from "@/db/users";

export default async function Dashboard() {
  const session = await auth();
  if (!session) return <NotAuth />;
.... other code 

}
Avatar
show auth()
Avatar
HavanaOP
auth.ts

import NextAuth, { User } from "next-auth";
import Google from "next-auth/providers/google";

interface CustomUser extends User {
  role?: string;
}

export const allowedEmails = [
  {
    email: "test@gmail.com",
    role: "admin",
  }
];

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [Google],
  callbacks: {
    async signIn({ user }: { user: CustomUser }) {
      const allowedUser = allowedEmails.find(
        (allowedEmail) => allowedEmail.email === user.email
      );
      if (allowedUser) {
        user.role = allowedUser.role;
        return true;
      } else {
        return false;
      }
    },
    async jwt({ token, user }: { token: any; user: CustomUser }) {
      if (user) {
        token.role = user.role;
      }
      return token;
    },
    async session({ session, token }: { session: any; token: any }) {
      if (session.user) {
        session.user.role = token.role;
      }
      return session;
    },
  },
});
Avatar
Sphecid wasp
Hi lucky. i think this error seems like to happen because the header function is async function. please add this code below 28. const protoHeader = await headers().get('x-forwarded-proto');
Avatar
:/ op clearly mentioned they arent using headers?
its likely a thing with next auth and next v15 not matching
@Havana go through that thread
Avatar
HavanaOP
sure
Avatar
Sphecid wasp
U are right. I was wrong.
You have to check the next version.