How can i Get the user id from getServerSession(authoptions)
this authoption
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import prisma from '../../prisma/client';
import CredentialsProvider from 'next-auth/providers/credentials';
import { NextAuthOptions } from 'next-auth';
import bcrypt from 'bcrypt';
import { z } from 'zod';
const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
pages: {
signIn: '/auth/login',
},
providers: [
// GoogleProvider({
// clientId: process.env.GOOGLE_CLIENT_ID!,
// clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
// }),
CredentialsProvider({
name: 'Credentials',
credentials: {
email: {
label: 'Email',
type: 'email',
placeholder: 'Email',
},
password: {
label: 'Password',
type: 'password',
placeholder: 'Password',
},
},
async authorize(credentials, req) {
const parsedCredentials = z
.object({ email: z.string().email(), password: z.string().min(4) })
.safeParse(credentials);
if (parsedCredentials.success) {
if (!credentials?.email || !credentials.password) return null;
const user = await prisma.user.findUnique({
where: { email: credentials.email },
});
if (!user) return null;
const passwordsMatch = await bcrypt.compare(credentials.password, user.hashedPassword!);
return passwordsMatch ? user : null;
}
return null;
},
}),
],
session: {
strategy: 'jwt',
},
};
export default authOptions;
const session = await getServerSession(authOptions);
if (!session) return NextResponse.json({}, { status: 401 });
console.log(session.user);
this only has email,name, and image but I want to have id also
I’m using
“next”: “^14.0.4”,
“next-auth”: “^4.24.5”
Thanks