Skip to content

Commit f1d140d

Browse files
Merge pull request #2187 from Web3Auth/feat/ssr
Adds ssr support in web3auth SDK
2 parents 108af9c + b76bedb commit f1d140d

File tree

72 files changed

+9986
-2640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+9986
-2640
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Hop on to the [Web3Auth Dashboard](https://dashboard.web3auth.io/) and create a
5151
Web3Auth needs to initialise as soon as your app loads up to enable the user to log in. Preferably done within a constructor, initialisation is the step where you can pass on all the configurations for Web3Auth you want. A simple integration for Ethereum blockchain will look like this:
5252

5353
```js
54-
import { Web3Auth } from "@web3auth/modal";
54+
import { Web3Auth } from "web3auth";
5555

5656
//Initialize within your constructor
5757
const web3auth = new Web3Auth({
@@ -62,7 +62,7 @@ const web3auth = new Web3Auth({
6262
},
6363
});
6464

65-
await web3auth.initModal();
65+
await web3auth.init();
6666
```
6767

6868
### Login your User

demo/nextjs-ssr-app/.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"ignorePatterns": ["*.config.js"]
4+
}

demo/nextjs-ssr-app/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo

demo/nextjs-ssr-app/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Web3Auth (`@web3auth/modal`) x EVM x Next.js
2+
3+
[![Web3Auth](https://img.shields.io/badge/Web3Auth-SDK-blue)](https://web3auth.io/docs/sdk/pnp/web/modal)
4+
[![Web3Auth](https://img.shields.io/badge/Web3Auth-Community-cyan)](https://community.web3auth.io)
5+
6+
[Join our Community Portal](https://community.web3auth.io/) to get support and stay up to date with the latest news and updates.
7+
8+
This example demonstrates how to use Web3Auth with EVM in Next.js
9+
10+
## How to Use
11+
12+
### One-Click Deploy to Vercel
13+
14+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FWeb3Auth%2Fweb3auth-pnp-examples%2Ftree%2Fmain%2Fweb-modal-sdk%2Fquick-starts%2Fnextjs-modal-quick-start&project-name=w3a-nextjs-modal&repository-name=w3a-nextjs-modal)
15+
16+
### Download Manually
17+
18+
```bash
19+
npx degit Web3Auth/web3auth-pnp-examples/web-no-modal-sdk/quick-starts/nextjs-no-modal-quick-start w3a-example
20+
```
21+
22+
Install & Run:
23+
24+
```bash
25+
cd w3a-example
26+
npm install
27+
npm run dev
28+
# or
29+
cd w3a-example
30+
yarn
31+
yarn dev
32+
```
33+
34+
## Important Links
35+
36+
- [Website](https://web3auth.io)
37+
- [Docs](https://web3auth.io/docs)
38+
- [Guides](https://web3auth.io/docs/guides)
39+
- [SDK / API References](https://web3auth.io/docs/sdk)
40+
- [Pricing](https://web3auth.io/pricing.html)
41+
- [Community Portal](https://community.web3auth.io)
25.3 KB
Binary file not shown.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
.container {
2+
width: 60%;
3+
margin: auto;
4+
padding: 0 2rem;
5+
}
6+
7+
.main {
8+
min-height: 100vh;
9+
padding: 4rem 0;
10+
flex: 1;
11+
display: flex;
12+
flex-direction: column;
13+
justify-content: center;
14+
align-items: center;
15+
}
16+
17+
.title {
18+
line-height: 1.15;
19+
font-size: 3rem;
20+
text-align: center;
21+
margin: 50px;
22+
}
23+
24+
.title a {
25+
color: #0070f3;
26+
text-decoration: none;
27+
}
28+
29+
.console {
30+
max-width: 100%;
31+
}
32+
33+
.code {
34+
background: #fafafa;
35+
border-radius: 5px;
36+
padding: 0.75rem;
37+
font-size: 1.1rem;
38+
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
39+
overflow-wrap: break-word;
40+
}
41+
42+
.grid {
43+
display: flex;
44+
align-items: center;
45+
flex-direction: column;
46+
}
47+
48+
.setting {
49+
display: flex;
50+
align-items: center;
51+
flex-direction: column;
52+
padding: 20px;
53+
margin: 30px 0;
54+
background: #f4f5f7;
55+
border: 1px solid #ebecf0;
56+
border-radius: 5px;
57+
}
58+
59+
.card {
60+
margin: 0.5rem;
61+
padding: 0.7rem;
62+
text-align: center;
63+
color: #0070f3;
64+
text-decoration: none;
65+
border: 1px solid #0070f3;
66+
border-radius: 10px;
67+
transition: color 0.15s ease, border-color 0.15s ease;
68+
width: 100%;
69+
}
70+
71+
.card:hover,
72+
.card:focus,
73+
.card:active {
74+
cursor: pointer;
75+
background-color: #fafafa;
76+
}
77+
78+
.row {
79+
display: flex;
80+
margin-bottom: 0.5rem;
81+
width: 100%;
82+
}
83+
.label {
84+
flex-basis: 45%;
85+
padding-right: 10px;
86+
display: flex;
87+
align-items: center;
88+
justify-content: right;
89+
font-weight: bold;
90+
}
91+
92+
.select {
93+
flex-basis: 30%;
94+
text-align: left;
95+
padding: 0.3rem 0.8rem;
96+
font-size: 1rem;
97+
border-radius: 8px;
98+
}
99+
100+
.footer {
101+
display: flex;
102+
flex: 1;
103+
padding: 2rem 0;
104+
border-top: 1px solid #eaeaea;
105+
justify-content: center;
106+
align-items: center;
107+
margin-top: 10rem;
108+
}
109+
110+
.footer a {
111+
display: flex;
112+
justify-content: center;
113+
align-items: center;
114+
flex-grow: 1;
115+
}
116+
117+
.logo {
118+
height: 1.5rem;
119+
margin-left: 0.5rem;
120+
}
121+
122+
/* @media (max-width: 1200px) {
123+
.container {
124+
width: 100%;
125+
}
126+
} */

demo/nextjs-ssr-app/app/layout.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import "./globals.css";
2+
3+
import { Inter } from "next/font/google";
4+
5+
import Provider from "@/components/provider";
6+
import { cookieToWeb3AuthState } from "@web3auth/modal";
7+
import { headers } from "next/headers";
8+
import { cookieToInitialState } from "wagmi";
9+
10+
const inter = Inter({ subsets: ["latin"] });
11+
12+
export const metadata = {
13+
title: "Web3Auth NextJS Quick Start",
14+
description: "Web3Auth NextJS Quick Start",
15+
};
16+
17+
export default function RootLayout({ children }: { children: React.ReactNode }) {
18+
const web3authInitialState = cookieToWeb3AuthState((headers()).get('cookie'))
19+
console.log("web3authInitialState", web3authInitialState)
20+
return (
21+
<html lang="en">
22+
<body className={inter.className}>
23+
<Provider web3authInitialState={web3authInitialState}>{children}</Provider>
24+
</body>
25+
</html>
26+
);
27+
}

demo/nextjs-ssr-app/app/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use client";
2+
3+
import Main from "@/components/Main";
4+
5+
export default function Home() {
6+
return <Main />
7+
}

0 commit comments

Comments
 (0)