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.
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.
Thanks for your question, Nestor! Here’s a summary for the support team and some guidance for you:
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:
When initializing Web3Auth, set the following options:
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.Web3Auth provides a Next.js Quick Start guide and React SDK docs 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
:
import { Web3AuthProvider } from "@web3auth/modal/react";
import web3AuthContextConfig from "../web3authContext"; // your config file
function MyApp({ Component, pageProps }) {
return (
<Web3AuthProvider config={web3AuthContextConfig}>
<Component {...pageProps} />
</Web3AuthProvider>
);
}
export default MyApp;
storageType
is set to "local"
and the provider is at the app root, the session will persist across all Next.js pages.useWeb3Auth
) as described in the React SDK docs.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