getServerSession null when calling from a server component
Unanswered
Brouillard posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/278244603142995972/dc052221f3050fdee6bd9bdcc2b013ba.webp?size=256)
BrouillardOP
Hi there I'm calling a route both from a server component and from a client component.
From Client component all goes well, but when I call it from a sever component the session is null
here's the route :
From Client component all goes well, but when I call it from a sever component the session is null
here's the route :
import type {
GetServerSidePropsContext,
NextApiRequest,
NextApiResponse,
} from "next"
import type { NextAuthOptions } from "next-auth"
import { getServerSession } from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import EmailProvider from "next-auth/providers/email"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export const config = {
pages: {
signIn: "/login",
signOut: "/auth/signout",
},
adapter: PrismaAdapter(prisma),
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {},
async authorize(credentials: any): Promise<any> {
const user = JSON.parse(credentials.user)
},
}),
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: Number(process.env.EMAIL_SERVER_PORT),
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
}),
],
secret: process.env.NEXTAUTH_SECRET,
} satisfies NextAuthOptions
// Use it in server contexts
export function auth(
...args:
| [GetServerSidePropsContext["req"], GetServerSidePropsContext["res"]]
| [NextApiRequest, NextApiResponse]
| []
) {
return getServerSession(...args, config)
}
6 Replies
![Avatar](https://cdn.discordapp.com/avatars/278244603142995972/dc052221f3050fdee6bd9bdcc2b013ba.webp?size=256)
BrouillardOP
please help
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Komondor
Is the nextauth session cookie set?
![Avatar](https://cdn.discordapp.com/avatars/278244603142995972/dc052221f3050fdee6bd9bdcc2b013ba.webp?size=256)
BrouillardOP
how can I check that ?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Komondor
in chrome dev tools
under Application -> Cookies
![Image](https://cdn.discordapp.com/attachments/1171847335198851234/1172303168005210183/image.png?ex=655fd367&is=654d5e67&hm=1fbad3ed7cea5056564db4ff9064f7f063c958c63074b428adb448e74ecf67cd&)