Skip to content

Commit c8edf2d

Browse files
Firgrepndom91
andauthored
docs: added callout re getServerSession nextjs.md (#8964)
added callout re getServerSession nextjs.md Added an admonition/callout that specifies there is a contrast between the returning object using useSession (client components) and getServerSession (server components). Where the former appears to always return a session object, the latter only returns an object where there a authenticated cookies present, otherwise it returns null. I was expecting getServerSession to behave exactly like useSession, but this appears not to be the case and I would have appreciated if this was highlighted somewhere. Co-authored-by: Nico Domino <[email protected]>
1 parent 9676afb commit c8edf2d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docs/docs/configuration/nextjs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export default async function Page() {
9898
}
9999
```
100100

101+
:::info
102+
In contrast to `useSession`, which will return a `session` object whether or not a user has logged in (whether or not cookies are present), `getServerSession` only returns a `session` object when a user has logged in (only when authenticated cookies are present), otherwise, it returns `null`.
103+
:::
104+
101105
:::warning
102106
Currently, the underlying Next.js `cookies()` method [only provides read access](https://beta.nextjs.org/docs/api-reference/cookies) to the request cookies. This means that the `expires` value is stripped away from `session` in Server Components. Furthermore, there is a hard expiry on sessions, after which the user will be required to sign in again. (The default expiry is 30 days).
103107
:::

0 commit comments

Comments
 (0)