#Type is not assignable

11 messages · Page 1 of 1 (latest)

green ermine
#

The error is:

Type '{ email: string; password: string; }' is not assignable to type 'UserWhereUniqueInput'.
Object literal may only specify known properties, and 'password' does not exist in type 'UserWhereUniqueInput'.ts(2322)
index.d.ts(4771, 5): The expected type comes from property 'where' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null

The error is on line 79 ( password: password, )

Runs fine in Dev but won't build. Fairly new to TS / React

#

The total file is

`import { PrismaAdapter } from '@next-auth/prisma-adapter';
import { PrismaClient } from '@prisma/client';
import NextAuth from "next-auth";
import {
type DefaultSession,
} from "next-auth";
import EmailProvider from "next-auth/providers/email";
import DiscordProvider from "next-auth/providers/discord";
import AzureADProvider from "next-auth/providers/azure-ad";
import CredentialsProvider from "next-auth/providers/credentials";

const prisma = new PrismaClient();

declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
}
}

const handler = NextAuth({
session: {
strategy: "jwt",
maxAge: 1 * 24 * 60 * 60,
updateAge: 4 * 60 * 60,
generateSessionToken: () => {
return self.crypto.randomUUID?.()
}

},
providers: [
  
    DiscordProvider({
        clientId: process.env.DISCORD_CLIENT_ID as string,
        clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
    }),
    AzureADProvider({
        name: "Microsoft 365",
        clientId: process.env.AZURE_AD_CLIENT_ID as string,
        clientSecret: process.env.AZURE_AD_CLIENT_SECRET as string,
        tenantId: process.env.AZURE_AD_TENANT_ID,
    }),
    EmailProvider({
        server: {
        host: process.env.EMAIL_SERVER_HOST,
        port: process.env.EMAIL_SERVER_PORT,
        auth: {
            user: process.env.EMAIL_SERVER_USER,
            pass: process.env.EMAIL_SERVER_PASSWORD,
        },
        },
        from: process.env.EMAIL_FROM,
    }),
    CredentialsProvider({
      // The name to display on the sign in form (e.g. "Sign in with...")
      name: "Credentials",
      // `credentials` is used to generate a form on the sign in page.
      // You can specify which fields should be submitted, by adding keys to the `credentials` object.
      // e.g. domain, username, password, 2FA token, etc.
      // You can pass any HTML attribute to the <input> tag through the object.
      credentials: {
        email: { label: "Email", type: "text", placeholder: "jsmith@example.com" },
        password: { label: "Password", type: "password" }
      },
      async authorize(credentials: { email: string; password: string } | undefined, req) {
        const { email, password } = credentials || { email: "", password: "" }; // Add default values to handle undefined
    
        try {
          // Use Prisma to query the user with the provided username and password
          const user = await prisma.user.findUnique({
            where: {
              email: email,
              password: password,
            },
          });
    
          if (user) {
            // If the user is found, return it. Any object returned will be saved in the `user` property of the JWT.
            return user;
          } else {
            // If the user is not found, return null to indicate login failure.
            return null;
          }
        } catch (error) {
          // Handle any potential errors that might occur during the database query.
          console.error('Error fetching user:', error);
          throw new Error('Error fetching user'); // You can also Reject this callback with an Error to redirect to the error page.
        }
      },
    })        
],
adapter: PrismaAdapter(prisma),

});

export { handler as GET, handler as POST };`

#

I THINK this is a typescript thing (i'm just playing so not bothering with password encryption or anything like that yet)

cinder mesa
#

what is UserWhereUniqueInput? something prisma generated, i imagine? can you share what that type looks like?

green ermine
#

not sure - it dosen't look like it exists in the project at all

#

looks like it's part of the prisma client api

cinder mesa
#

the fact that the error message is calling it out means it must exist somewhere. if you go to the definition of prisma.user.findUnique you should see it

cinder mesa
green ermine
#

okay, thanks that gives me a jumping point, looks like it's part of the prisma API - I'll dig in there a little further

green ermine
#

Prisma findUnique needed to be changed - I went with findFirst to resolve