Skip to content

Commit 1b64d6e

Browse files
committed
[Playground] Feature: Adds smart account auth (#5979)
--- title: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" --- If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a new smart account authentication feature in the `playground-web` application, allowing users to sign in using Ethereum. It adds a new component for the authentication button and integrates it into the main application page. ### Detailed summary - Added `SmartAccountAuthButton` component for Ethereum authentication. - Implemented `SmartAccountAuthPreview` to display JWT cookies. - Updated `page.tsx` to include `SmartAccountAuth` section. - Added a code example demonstrating the authentication button usage. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent f1afa3b commit 1b64d6e

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

apps/playground-web/src/app/connect/auth/page.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BasicAuthPreview } from "@/components/auth/basic-auth";
22
import { GatedContentPreview } from "@/components/auth/gated-content";
3+
import { SmartAccountAuthPreview } from "@/components/auth/smart-account-auth";
34
import { CodeExample } from "@/components/code/code-example";
45
import ThirdwebProvider from "@/components/thirdweb-provider";
56
import { metadataBase } from "@/lib/constants";
@@ -39,6 +40,12 @@ export default function Page() {
3940
<section className="space-y-8">
4041
<GatedContent />
4142
</section>
43+
44+
<div className="h-14" />
45+
46+
<section className="space-y-8">
47+
<SmartAccountAuth />
48+
</section>
4249
</main>
4350
</ThirdwebProvider>
4451
);
@@ -148,3 +155,58 @@ export async function GatedContentPreview() {
148155
</>
149156
);
150157
}
158+
159+
function SmartAccountAuth() {
160+
return (
161+
<>
162+
<div className="space-y-2">
163+
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl">
164+
Smart Account Auth
165+
</h2>
166+
<p className="max-w-[600px]">
167+
Use smart accounts with Sign in with Ethereum (SIWE)
168+
</p>
169+
</div>
170+
171+
<CodeExample
172+
preview={<SmartAccountAuthPreview />}
173+
code={`"use client";
174+
175+
import {
176+
generatePayload,
177+
isLoggedIn,
178+
login,
179+
logout,
180+
} from "@/app/connect/auth/server/actions/auth";
181+
import { THIRDWEB_CLIENT } from "@/lib/client";
182+
import { ConnectButton } from "thirdweb/react";
183+
import { defineChain } from "thirdweb";
184+
185+
export function AuthButton() {
186+
return (
187+
<ConnectButton
188+
client={THIRDWEB_CLIENT}
189+
accountAbstraction={{
190+
chain: defineChain(17000),
191+
sponsorGas: true
192+
}}
193+
auth={{
194+
// The following methods run on the server (not client)!
195+
isLoggedIn: async () => {
196+
const authResult = await isLoggedIn();
197+
if (!authResult) return false;
198+
return true;
199+
},
200+
doLogin: async (params) => await login(params),
201+
getLoginPayload: async ({ address }) => generatePayload({ address }),
202+
doLogout: async () => await logout(),
203+
}}
204+
/>
205+
);
206+
}
207+
`}
208+
lang="tsx"
209+
/>
210+
</>
211+
);
212+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use client";
2+
import {
3+
generatePayload,
4+
isLoggedIn,
5+
login,
6+
logout,
7+
} from "@/app/connect/auth/server/actions/auth";
8+
import { THIRDWEB_CLIENT } from "@/lib/client";
9+
import { defineChain } from "thirdweb";
10+
import { ConnectButton } from "thirdweb/react";
11+
12+
export function SmartAccountAuthButton() {
13+
return (
14+
<ConnectButton
15+
client={THIRDWEB_CLIENT}
16+
accountAbstraction={{
17+
chain: defineChain(17000),
18+
sponsorGas: true,
19+
}}
20+
auth={{
21+
isLoggedIn: (address) => isLoggedIn(address),
22+
doLogin: (params) => login(params),
23+
getLoginPayload: ({ address }) =>
24+
generatePayload({ address, chainId: 17000 }),
25+
doLogout: () => logout(),
26+
}}
27+
/>
28+
);
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";
2+
import { cookies } from "next/headers";
3+
import { cn } from "../../lib/utils";
4+
import { SmartAccountAuthButton } from "./smart-account-auth-button";
5+
6+
export async function SmartAccountAuthPreview() {
7+
const jwt = (await cookies()).get("jwt");
8+
return (
9+
<div className="flex flex-col gap-5">
10+
<div className="mx-auto">
11+
<SmartAccountAuthButton />
12+
</div>
13+
{jwt && !!jwt.value && (
14+
<table className="table-auto border-collapse rounded-lg backdrop-blur">
15+
<tbody>
16+
{Object.keys(jwt).map((key) => (
17+
<tr key={key} className="">
18+
<td className="rounded border p-2">{key}</td>
19+
<td
20+
className={cn(
21+
"max-h-[200px] max-w-[250px] overflow-y-auto whitespace-normal break-words border p-2",
22+
{
23+
"text-xs": key === "value",
24+
},
25+
)}
26+
>
27+
{jwt[key as keyof RequestCookie]}
28+
</td>
29+
</tr>
30+
))}
31+
</tbody>
32+
</table>
33+
)}
34+
</div>
35+
);
36+
}

0 commit comments

Comments
 (0)