Next.js Discord

Discord Forum

Type 'OmitWithTag<typeof import()

Unanswered
Japanese Bobtail posted this in #help-forum
Open in Discord
Japanese BobtailOP
"config" | "generateStaticParams" | "revalidate" | "dynamic" | ... 11 more ... | "PATCH", "">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'handler' is incompatible with index signature.
Type 'NextAuthResult' is not assignable to type 'never'.

5 Replies

Japanese BobtailOP
.next/types/app/api/auth/[...nextauth]/route.ts:12:13
import NextAuth from "next-auth";
import { auth } from "@/auth";

export const handler = NextAuth(auth);
export { handler as GET, handler as POST };
literallly THE WHOLE DAMN FILE
auth.ts

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import bcrypt from "bcryptjs";
import prisma from "@/utils/db";
import { nanoid } from "nanoid";

export const auth = NextAuth({
  providers: [
    CredentialsProvider({
      id: "credentials",
      name: "Credentials",
      credentials: {
        email: { label: "Email", type: "text" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        if (!credentials?.email || !credentials.password) {
          throw new Error("No credentials provided");
        }

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

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

        const isPasswordCorrect = await bcrypt.compare(
          credentials.password,
          user.password
        );

        if (!isPasswordCorrect) {
          return null;
        }

        return user;
      },
    }),
    GithubProvider({
      clientId: process.env.GITHUB_ID ?? "",
      clientSecret: process.env.GITHUB_SECRET ?? "",
    }),
    GoogleProvider({
      clientId: process.env.GOOGLE_ID ?? "",
      clientSecret: process.env.GOOGLE_SECRET ?? "",
    }),
  ],
  callbacks: {
    async signIn({ user, account, profile, email, credentials }) {
      if (!account || account.provider === "credentials") {
        return true;
      }

      const existingUser = await prisma.user.findFirst({
        where: { email: user.email ?? "" },
      });

      if (!existingUser) {
        await prisma.user.create({
          data: { id: nanoid(), email: user.email ?? "" },
        });
      }

      return true;
    },
  },
});