---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk-react/functions/useSession.md
---
[Reference](../../../index.md) / [@getenginex/sdk-react](../index.md) / useSession

# useSession()

> **useSession**(): [`Session`](../../sdk/interfaces/Session.md)

Current player session, reactive to login, logout and a renewal that changes the identity. Uses
`useSyncExternalStore` over `client.session`: the reference only changes when the session changes.

On the server and during hydration it returns `{ status: 'anonymous' }` (or the
[EnginexProvider](EnginexProvider.md)'s `initialSession`); the real session appears right after hydration.

## Returns

[`Session`](../../sdk/interfaces/Session.md)

The `Session` of the nearest [EnginexProvider](EnginexProvider.md)'s client.

## Throws

If called outside an `EnginexProvider`.

## Example

```ts
const session = useSession()
if (session.status === 'authenticated') return <Wallet userId={session.userId} />
return <LoginButton />
```
