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
).
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
},
}),
],
});