Next.js Discord

Discord Forum

NextAuth Adapter import error

Unanswered
Pacific sand lance posted this in #help-forum
Open in Discord
Avatar
Pacific sand lanceOP
Hi, i was trying to extend my NextAuth type (https://next-auth.js.org/getting-started/typescript) and i get an error after creating it regarding my PrismaAdapter

Type 'import("/something/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/something/node_modules/next-auth/adapters").Adapter'.
  The types returned by 'createUser(...)' are incompatible between these types.


This is my next-auth.d.ts code
import NextAuth from "next-auth/next";

declare module "next-auth" {
    interface User {
        username: string
    }
    interface Session {
        user: User & {
            username: string
        }
        token: {
            username: string
        }
    }
}


This is my auth.ts code
export const authOptions: NextAuthOptions = {
    adapter: PrismaAdapter(prisma),
    secret: process.env.NEXTAUTH_SECRET,
    session: {
        //
    },
    pages: {
        //
    },
    providers: [
        //
    ],
    callbacks: {
        async jwt({token, user}) {
            if(user) {
                return {
                    ...token,
                    username: user.username
                }
            }
            return token
        },
        async session({session, user, token}) {
            return {
                ...session,
                user: {
                    ...session.user,
                    username: token.username
                }
            }
        },
    }
}

0 Replies