# Session management

**URL:** <https://builder.metamask.io/t/session-management/962>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [September 4, 2025, 12:26pm UTC](https://builder.metamask.io/t/session-management/962 "2025-09-04T12:26:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nestora](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@nestora](https://builder.metamask.io/u/nestora)\
**Post date:** [September 4, 2025, 12:26pm UTC](https://builder.metamask.io/t/session-management/962/1 "2025-09-04T12:26:29Z")

</div>

> **🏛 Content from Web3Auth Community**
> 
> This topic was originally posted by **nestora** on 9/4/2025.  
> This content has been migrated from our previous community forum to preserve valuable discussions.

* * *

Hi,

Do you have example of implementing session management using Next.JS. Basically, an app build in NextJS with multiple pages and session persists across the pages.

---

<div class="post-metadata">

**Author:** ![w3abot](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@w3abot](https://builder.metamask.io/u/w3abot)\
**Post date:** [September 4, 2025, 12:29pm UTC](https://builder.metamask.io/t/session-management/962/2 "2025-09-04T12:29:02Z")

</div>

Thanks for your question, Nestor! Here’s a summary for the support team and some guidance for you:

* * *

## User Request Summary

- **SDK/Integration:** Web3Auth Plug and Play (PnP) SDK
- **Platform:** Next.js (Web, React-based framework)
- **Topic:** Session management—how to persist user sessions across multiple pages in a Next.js app using Web3Auth.
- **User Asks:** Looking for an example or best practice for session management with Web3Auth in a Next.js application, ensuring the session persists across page navigation.

* * *

## Guidance & Documentation

Web3Auth session management in web apps (including Next.js) is handled via configuration options like `sessionTime` and `storageType` in the Web3Auth SDK. Here’s how you can achieve persistent sessions:

### 1. Configure Web3Auth for Persistent Sessions

When initializing Web3Auth, set the following options:

```js
const web3AuthOptions = {
  clientId: "YOUR_CLIENT_ID",
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
  sessionTime: 86400 * 7, // 7 days in seconds
  storageType: "local", // 'local' persists across tabs and reloads
};

```

- `storageType: "local"` ensures the session persists across browser tabs and page reloads.
- `sessionTime` controls how long the session remains valid.

### 2. Next.js Integration Example

Web3Auth provides a [Next.js Quick Start guide](https://web3auth.io/docs/quick-start/web/nextjs) and [React SDK docs](https://web3auth.io/docs/sdk/web/react#enterprise-menu) that are directly applicable. The session will persist as long as you use the same `Web3AuthProvider` context at the top level (e.g., in `_app.js` or `_app.tsx`).

Example setup in `_app.tsx`:

```tsx
import { Web3AuthProvider } from "@web3auth/modal/react";
import web3AuthContextConfig from "../web3authContext"; // your config file

```

### 3. Session Persistence

- As long as `storageType` is set to `"local"` and the provider is at the app root, the session will persist across all Next.js pages.
- If you need to access the authentication state or user info on different pages, use the Web3Auth React hooks (`useWeb3Auth`) as described in the [React SDK docs](https://web3auth.io/docs/sdk/web/react#enterprise-menu).

* * *

## References

- [Web3Auth Advanced Session Management](https://web3auth.io/docs/sdk/web/js/advanced#session-management)
- [Web3Auth Next.js Quick Start](https://web3auth.io/docs/quick-start/web/nextjs)
- [Web3Auth React SDK Docs](https://web3auth.io/docs/sdk/web/react#enterprise-menu)

* * *

If you need a more detailed code example or run into any issues with session persistence, let us know your current code setup or any specific errors you encounter!

> Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

> Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. [Web3Auth Developer Office Hours](https://web3auth.io/community/t/web3auth-developer-office-hours/8777)
