Skip to content

Commit 5baefe2

Browse files
[Connect] Redesign sidebar and update wallet documentation
1 parent a7544f7 commit 5baefe2

File tree

14 files changed

+2066
-777
lines changed

14 files changed

+2066
-777
lines changed

apps/portal/src/app/connect/account-abstraction/get-started/page.mdx

Lines changed: 89 additions & 307 deletions
Large diffs are not rendered by default.
-867 KB
Binary file not shown.

apps/portal/src/app/connect/auth/page.mdx

Lines changed: 73 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -17,152 +17,123 @@ import { GraduationCap } from "lucide-react";
1717

1818
export const metadata = createMetadata({
1919
image: {
20-
title: "thirdweb Auth",
20+
title: "Sign in with Ethereum",
2121
icon: "wallets",
2222
},
23-
title: "thirdweb Auth",
23+
title: "Sign in with Ethereum",
2424
description:
25-
"Auth allows anyone to integrate passwordless web3-native authentication and authorization into their applications.",
25+
"Sign in with Ethereum allows anyone to integrate passwordless web3-native authentication and authorization into their applications.",
2626
});
2727

28-
# Overview
28+
# Sign in with Ethereum
2929

30-
Auth allows anyone to integrate passwordless web3-native authentication and authorization into their applications. Users can then **login using any thirdweb wallet** (in-app, browser, or smart wallet).
30+
Sign in with Ethereum (SIWE) allows anyone to integrate passwordless web3-native authentication and authorization into their applications. Users can then **login using any thirdweb wallet** (in-app, browser, or smart wallet).
3131

3232
This allows developers to create a familiar, secure authentication flow that works with traditional backends while leveraging the features of a web3 application.
3333

3434
---
3535

36-
# Get Started
36+
<Tabs defaultValue="client">
3737

38-
<InstallTabs
39-
npm="npm i thirdweb"
40-
yarn="yarn add thirdweb"
41-
pnpm="pnpm i thirdweb"
42-
bun="bun i thirdweb"
43-
/>
38+
<TabsList>
39+
<TabsTrigger value="client">Client</TabsTrigger>
40+
<TabsTrigger value="server">Server</TabsTrigger>
41+
</TabsList>
4442

45-
## Get Your Client ID
43+
<TabsContent value="client">
4644

47-
To use Auth in your app, you'll need a client ID. You can get one for free on [your thirdweb dashboard](https://thirdweb.com/create-api-key).
45+
At the root of your React application:
4846

49-
## Setting Up Auth
47+
```tsx
48+
import { ThirdwebProvider } from "thirdweb/react";
5049

51-
<Tabs defaultValue="react">
50+
export default function App() {
51+
return <ThirdwebProvider>{/* Your app here */}</ThirdwebProvider>;
52+
}
53+
```
5254

53-
<TabsList>
54-
<TabsTrigger value="react">React</TabsTrigger>
55-
<TabsTrigger value="typescript">TypeScript</TabsTrigger>
56-
</TabsList>
55+
In your `components` directory:
5756

58-
<TabsContent value="react">
5957
```tsx
60-
import { ThirdwebProvider, ConnectButton } from "thirdweb/react";
58+
import { ConnectButton } from "thirdweb/react";
6159
import { createThirdwebClient } from "thirdweb";
62-
import { createAuth } from "thirdweb/auth";
6360

64-
const client = createThirdwebClient({
65-
clientId: '1234567890', // get yours by creating a project on https://thirdweb.com/create-api-key
66-
});
67-
68-
const thirdwebAuth = createAuth({
69-
domain: 'localhost:3000',
70-
client,
71-
adminAccount: privateKeyToAccount({ client, privateKey }),
72-
});
73-
74-
export default function App() {
75-
const [loggedIn, setLoggedIn] = useState(false);
76-
return (
77-
// The ThirdwebProvider should be at the root of your application, but the ConnectButton can be anywhere
78-
<ThirdwebProvider>
79-
<ConnectButton
80-
client={client}
81-
auth={{
82-
getLoginPayload: async (params) => {
83-
// here you should call your backend, using generatePayload to return
84-
// a SIWE compliant login payload to the client
85-
return thirdwebAuth.generatePayload(params)
86-
},
87-
doLogin: async (params) => {
88-
// here you should call your backend to verify the signed payload passed in params
89-
// this will verify that the signature matches the intended wallet
90-
const verifiedPayload = await thirdwebAuth.verifyPayload(params);
91-
setLoggedIn(verifiedPayload.valid)
92-
},
93-
isLoggedIn: async () => {
94-
// here you should ask you backend if the user is logged in
95-
// can use cookies, storage, or your method of choice
96-
return loggedIn;
97-
},
98-
doLogout: async () => {
99-
// here you should call your backend to logout the user if needed
100-
// and delete any local auth tokens
101-
setLoggedIn(false);
102-
}
103-
}}
104-
/>
105-
</ThirdwebProvider>
106-
);
61+
const client = createThirdwebClient({ clientId });
62+
63+
export default function Connect() {
64+
<ConnectButton
65+
client={client}
66+
auth={{
67+
getLoginPayload: async (params) => {
68+
const address = params.address;
69+
// fetch the login payload here using address from your server
70+
},
71+
doLogin: async (params) => {
72+
// send the signed login payload (params) to your server to verify the signature
73+
},
74+
isLoggedIn: async () => {
75+
// fetch the user's login status from your server
76+
},
77+
doLogout: async () => {
78+
// send a logout request to your server
79+
},
80+
}}
81+
/>;
10782
}
10883
```
84+
10985
</TabsContent>
11086

111-
<TabsContent value="typescript">
87+
<TabsContent value="server">
11288

11389
```ts
90+
import { createThirdwebClient } from "thirdweb";
11491
import { createAuth } from "thirdweb/auth";
11592

11693
const client = createThirdwebClient({
117-
clientId: "1234567890", // get yours at https://thirdweb.com/create-api-key
94+
secretKey: "<your-secret-key>", // get yours on your thirdweb dashboard
11895
});
11996

120-
const auth = createAuth({
121-
domain: "localhost:3000",
122-
adminAccount: privateKeyToAccount({ client, privateKey }),
97+
const thirdwebAuth = createAuth({
98+
domain: "localhost:3000", // your domain
12399
client,
124100
});
125101

126-
// 1. generate a login payload on the server
127-
const loginPayload = await auth.generatePayload({
128-
address: "0x123...",
129-
chain: 1,
130-
});
102+
// handle the login payload generation on your server
103+
// example: /api/generate-login-payload
104+
export async function generateLoginPayload(address: string) {
105+
return thirdwebAuth.generatePayload({ address });
106+
}
131107

132-
// 2. sign the login payload on the client
133-
const signature = await auth.signPayload({
134-
payload: loginPayload,
135-
account: userAccount,
136-
});
108+
// handle the login payload verification on your server
109+
// example: /api/verify-login-payload
110+
export async function verifyLoginPayload(payload: string, signature: string) {
111+
// verify the payload and signature
112+
const verifiedPayload = await thirdwebAuth.verifyPayload({ payload, signature });
137113

138-
// 3. verify the login payload and signature on the server
139-
const verifiedPayload = await auth.verifyPayload({
140-
payload: loginPayload,
141-
signature,
142-
});
114+
// if the payload is invalid, throw an error
115+
if(!verifiedPayload.valid) {
116+
throw new Error("Invalid signature");
117+
}
143118

144-
// 4. generate a JWT for the client
145-
const jwt = await auth.generateJWT({ payload: verifiedPayload });
119+
// Optionally, handle the JWT generation on your server for the client to use for subsequent calls to your server
120+
const jwt = await thirdwebAuth.generateJWT({ payload: verifiedPayload });
146121

147-
// 5. set the JWT as a cookie or store it another way
122+
return {
123+
valid: verifiedPayload.valid,
124+
jwt, // can also be stored in a cookie or another way
125+
};
126+
}
148127

149-
// 6. authenticate the client based on the JWT on subsequent calls
150-
const { valid, parsedJWT } = await auth.verifyJWT({ jwt });
128+
// handle the JWT verification on your server sent by the client
129+
// typically in a middleware
130+
export async function verifyJWT(jwt: string) {
131+
return thirdwebAuth.verifyJWT({ jwt });
132+
}
151133
```
152134

153135
</TabsContent>
154136

155-
<Callout variant="warning" title="Deploying to Production">
156-
These examples are intended to get up and running quickly, but aren't secure
157-
for production. Before deploying your app to real users, checkout out our
158-
walkthrough on [Deploying to
159-
Production](/connect/auth/deploying-to-production).
160-
</Callout>
161-
162-
### Auth with Smart Accounts (Account Abstraction)
163-
164-
When using Auth with a smart account, you **must** specify a client (on `createAuth`) and a chain ID (on `generatePayload`). The smart account is deployed on a specific chain and the payload must reflect that, and the client is needed to call the wallet contract to verify the signature.
165-
166137
</Tabs>
167138

168139
## Templates

0 commit comments

Comments
 (0)