Skip to content

Commit e002335

Browse files
committed
Add SSR to nextjs example
1 parent c78a6ef commit e002335

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

quick-starts/nextjs-quick-start/app/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from "react";
22
// IMP START - Quick Start
33
import Provider from "../components/provider";
4+
import { cookieToWeb3AuthState } from "@web3auth/modal";
45
// IMP END - Quick Start
56
import "./globals.css";
67

78
import { Inter } from "next/font/google";
9+
import { headers } from "next/headers";
810

911
const inter = Inter({ subsets: ["latin"] });
1012

@@ -15,10 +17,12 @@ export const metadata = {
1517

1618
// eslint-disable-next-line no-undef
1719
export default function RootLayout({ children }: { children: React.ReactNode }) {
20+
const web3authInitialState = cookieToWeb3AuthState((headers()).get('cookie'))
21+
1822
return (
1923
<html lang="en">
2024
<body className={inter.className}>
21-
<Provider>{children}</Provider>
25+
<Provider web3authInitialState={web3authInitialState}>{children}</Provider>
2226
</body>
2327
</html>
2428
);

quick-starts/nextjs-quick-start/components/provider.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
// IMP START - Setup Web3Auth Provider
44
import { Web3AuthProvider, type Web3AuthContextConfig } from "@web3auth/modal/react";
5-
import { WEB3AUTH_NETWORK } from "@web3auth/modal";
5+
import { IWeb3AuthState, WEB3AUTH_NETWORK } from "@web3auth/modal";
66
// IMP END - Setup Web3Auth Provider
77
// IMP START - Setup Wagmi Provider
88
import { WagmiProvider } from "@web3auth/modal/react/wagmi";
99
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
10+
import React from "react";
1011
// IMP END - Setup Wagmi Provider
1112

1213
// IMP START - Dashboard Registration
@@ -23,14 +24,16 @@ const web3AuthContextConfig: Web3AuthContextConfig = {
2324
clientId,
2425
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
2526
authBuildEnv: "testing",
27+
ssr: true,
28+
2629
}
2730
};
2831
// IMP END - Config
2932

30-
export default function Provider({ children }: { children: React.ReactNode }) {
31-
return (
33+
export default function Provider({ children, web3authInitialState }: { children: React.ReactNode, web3authInitialState: IWeb3AuthState | undefined }) {
34+
return (
3235
// IMP START - Setup Web3Auth Provider
33-
<Web3AuthProvider config={web3AuthContextConfig}>
36+
<Web3AuthProvider config={web3AuthContextConfig} initialState={web3authInitialState}>
3437
{/* // IMP END - Setup Web3Auth Provider */}
3538
{/*// IMP START - Setup Wagmi Provider*/}
3639
<QueryClientProvider client={queryClient}>

0 commit comments

Comments
 (0)