79730432

Date: 2025-08-09 05:27:56
Score: 0.5
Natty:
Report link

As stated in the official documentation, for next-auth@4 providers require an additional .default to work in Vite. This will no longer be necessary in next-auth@5 (authjs).

Reference

To remove the syntax error for using .default, add @ts-expect-error comment

import CredentialsProvider from "next-auth/providers/credentials";
import { NuxtAuthHandler } from "#auth";

export default NuxtAuthHandler({
  secret: process.env.AUTH_SECRET,
  providers: [
    // @ts-expect-error Need to use .default here for it to work during SSR. May be fixed via Vite at some point
    CredentialsProvider.default({
      id: "credentials",
      name: "Credentials",
      type: "credentials",
      credentials: {
        email: { label: "Email", type: "text", placeholder: "[email protected]" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials: { email: string; password: string }) {
        const res = await fetch(
          `${process.env.NUXT_PUBLIC_API_URL}/auth/login`,
          {
            method: "POST",
            body: JSON.stringify({
              email: credentials?.email,
              password: credentials?.password,
            }),
          }
        );
        console.log("res", res);
        // handle the rest
      },
    }),
  ],
});
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @ts-expect-error
  • Low reputation (1):
Posted by: Redoxx