How can i get user id from nextjs session

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!,
    // }),
      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) })
        if (parsedCredentials.success) {
          if (!credentials?.email || !credentials.password) return null;

          const user = await prisma.user.findUnique({
            where: { email: },

          if (!user) return null;

          const passwordsMatch = await, 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 });


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”


What page are you trying to get the on ? My understanding is that the ServerSession is primarily used to describe if the current session is authenticated and the session object is limited by design, for security. If you do need to add additional info to the session token check out the callbacks section. I believe you will need to add the user to the jwt and then add the token.user to the session. Be careful when doing this, you should expose as little auth info as possible for security.

Next Auth Callbacks

callbacks: {
 async jwt({ token, user }) {
      if (user) {
       // add user to token
        token.user = user;
      return Promise.resolve(token);
    session: async ({ session, token }) => {
      // session callback is called whenever a session for that particular user is checked
      // in above function we created token.user=user
      session.user = token.user;
      // you might return this in new version
      return Promise.resolve(session);