NextJS handler not setting the cookie in production

Hey šŸ‘‹ ,

My handler isn't setting the cookie on the client browser in production only.
I'm using next 15.3 and better auth ^1.2.7

Thanks for your help guys

here is my auth config§

export const auth = betterAuth({
  emailAndPassword: {
    enabled: false,
  },
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  plugins: [
    magicLink({
      sendMagicLink: async ({ email, url }) => {
        await resend.emails.send({
          from: "LGC <contact@lgc-supervision.site>",
          to: email,
          subject: "Lien de connexion Ć  LGC Supervision",
          react: await EmailTemplate({ url }),
        });
      },
    }),
    nextCookies(),
  ],
  callbacks: {
    async session({
      session,
      user,
    }: {
      session: CustomSession;
      user: { id: string };
    }) {
      const fullUser = await prisma.user.findUnique({
        where: { id: user.id },
        include: { company: true },
      }) as User & { company: Company | null };

      session.user.name = fullUser.name;
      session.user.email = fullUser.email;
      session.user.role = fullUser.role;

      if (fullUser.company) {
        session.user.company = {
          name: fullUser.company.name,
          color: fullUser.company.color,
        };
      }

      return session;
    },
  },
});


my route handler

import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";
 
export const { POST, GET } = toNextJsHandler(auth);
Was this page helpful?