Property 'id' does not exist on type ... error while next build
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "@/lib/prisma";
import DiscordProvider from "next-auth/providers/discord"
import { NextAuthOptions } from "next-auth";
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
}),
],
callbacks: {
async session({ session, user }) {
if (user && session) {
if (!session.user) {
session.user = {};
}
session.user.id = user.id;
}
return session;
},
},
};There is my code.
Also there is full error.
./app/api/auth/[...nextauth]/authOptions.ts:21:24
Type error: Property 'id' does not exist on type '{ name?: string | null | undefined; email?: string | null | undefined; image?: string | null | undefined; }'.
19 | session.user = {};
20 | }
> 21 | session.user.id = user.id;
| ^
22 | }
23 | return session;
24 | },1 Reply
@Cape lion ts
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "@/lib/prisma";
import DiscordProvider from "next-auth/providers/discord"
import { NextAuthOptions } from "next-auth";
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
}),
],
callbacks: {
async session({ session, user }) {
if (user && session) {
if (!session.user) {
session.user = {};
}
session.user.id = user.id;
}
return session;
},
},
};
There is my code.
Also there is full error.
./app/api/auth/[...nextauth]/authOptions.ts:21:24
Type error: Property 'id' does not exist on type '{ name?: string | null | undefined; email?: string | null | undefined; image?: string | null | undefined; }'.
19 | session.user = {};
20 | }
> 21 | session.user.id = user.id;
| ^
22 | }
23 | return session;
24 | },
// types/next-auth.d.ts
import NextAuth, { DefaultSession } from "next-auth"
declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
user: {
/** The user's postal address. */
id: string
} & DefaultSession["user"]
}
}try to declare it