Adaoter with Next-Auth not working
Unanswered
Red-billed Tropicbird posted this in #help-forum
Red-billed TropicbirdOP
I am getting this error on my adapter
Type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").Adapter'.
Types of property 'createUser' are incompatible.
'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/types").Awaitable<import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").AdapterUser>' is not assignable to type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/types").Awaitable<import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").AdapterUser>'.
Type 'AdapterUser' is not assignable to type 'Awaitable<AdapterUser>'.
Property 'role' is missing in type 'i
Type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").Adapter'.
Types of property 'createUser' are incompatible.
'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/types").Awaitable<import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.32.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").AdapterUser>' is not assignable to type 'import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/types").Awaitable<import("/Users/mehtabghuman/Desktop/ReZume/Rezume/node_modules/.pnpm/@auth+core@0.27.0_nodemailer@6.9.13/node_modules/@auth/core/adapters").AdapterUser>'.
Type 'AdapterUser' is not assignable to type 'Awaitable<AdapterUser>'.
Property 'role' is missing in type 'i
1 Reply
Red-billed TropicbirdOP
Here is the file Here is the file:
import { linkOAuthAccount } from "@/actions/auth"
import { getUserById } from "@/actions/user"
import { PrismaAdapter } from "@auth/prisma-adapter"
import NextAuth from "next-auth"
import { env } from "@/env.mjs"
import authConfig from "@/config/auth"
import { prisma } from "@/config/db"
export const {
handlers: { GET, POST },
auth,
signIn,
signOut,
} = NextAuth({
debug: env.NODE_ENV === "development",
pages: {
signIn: "/signin",
signOut: "/signout",
verifyRequest: "/signin/magic-link-signin",
},
secret: env.AUTH_SECRET,
session: {
strategy: "jwt",
maxAge: 30 * 24 * 60 * 60, // 30 daysd
updateAge: 24 * 60 * 60, // 24 hours
},
events: {
async linkAccount({ user }) {
if (user.id) await linkOAuthAccount({ userId: user.id })
},
},
callbacks: {
jwt({ token, user }) {
if (user) token.role = user.role
return token
},
session({ session, token }) {
session.user.role = token.role as "USER" | "ADMIN"
return session
},
async signIn({ user, account }) {
if (!user.id) return false
if (account?.provider !== "credentials") return true
const existingUser = await getUserById({ id: user.id })
return !existingUser?.emailVerified ? false : true
},
},
adapter: PrismaAdapter(prisma),
...authConfig,
})
import { linkOAuthAccount } from "@/actions/auth"
import { getUserById } from "@/actions/user"
import { PrismaAdapter } from "@auth/prisma-adapter"
import NextAuth from "next-auth"
import { env } from "@/env.mjs"
import authConfig from "@/config/auth"
import { prisma } from "@/config/db"
export const {
handlers: { GET, POST },
auth,
signIn,
signOut,
} = NextAuth({
debug: env.NODE_ENV === "development",
pages: {
signIn: "/signin",
signOut: "/signout",
verifyRequest: "/signin/magic-link-signin",
},
secret: env.AUTH_SECRET,
session: {
strategy: "jwt",
maxAge: 30 * 24 * 60 * 60, // 30 daysd
updateAge: 24 * 60 * 60, // 24 hours
},
events: {
async linkAccount({ user }) {
if (user.id) await linkOAuthAccount({ userId: user.id })
},
},
callbacks: {
jwt({ token, user }) {
if (user) token.role = user.role
return token
},
session({ session, token }) {
session.user.role = token.role as "USER" | "ADMIN"
return session
},
async signIn({ user, account }) {
if (!user.id) return false
if (account?.provider !== "credentials") return true
const existingUser = await getUserById({ id: user.id })
return !existingUser?.emailVerified ? false : true
},
},
adapter: PrismaAdapter(prisma),
...authConfig,
})