Next.js Discord

Discord Forum

NextAuth pages at `/app/api/[...nextAuth]` fail to load or compile

Unanswered
Ivory Gull posted this in #help-forum
Open in Discord
Ivory GullOP
Hey everyone!

I'm not exactly sure what is going on here. This is the error message I am receiving when trying to login with NextAuth. I am using this inside of a monorepo with turbo as well. Initially I was trying to use the next auth beta build, but have now moved to 4.20.1.

This is the error I am seeing, and I am posting relvenat files in the next message. If anyone has any tips I would really appreciate it!
 ✓ Compiled /signin in 327ms (541 modules)
 â—‹ Compiling /api/[...nextauth] ...
 ⨯ ../../node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>

2 Replies

Ivory GullOP
import { NextAuthConfig } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import database from "./utils/database";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { verifyPassword } from "@repo/auth";

export const authOptions: NextAuthConfig = {
session: {
strategy: "jwt",
},
adapter: PrismaAdapter(database),
pages: {
signIn: "/signin",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {},
password: {},
},
async authorize(credentials, req) {
if (!credentials.email !credentials.password) return null;

const user = await database.user.findFirst({
where: { email: credentials.email },
});

if (!user
!user?.password) {
return null;
}

const isValidPassword = await verifyPassword(
(credentials?.password as string) ?? "",
user.password
);

if (user && isValidPassword) {
return user;
} else {
return null;
}
},
}),
],
callbacks: {
async jwt({ token, account, user }) {
console.log("JWT:", token, account, user);
if (account && account.type === "credentials") {
token.userId = account.providerAccountId;
}
return token;
},
async session({ session, token, user }) {
console.log("SESSION:", session, token, user);
session.user.id = token.userId;
return session;
},
},
};

export default authOptions;
app/api/[...nextauth]/route.ts

import NextAuth from "next-auth";
import { authOptions } from "../../../auth";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };