-
Notifications
You must be signed in to change notification settings - Fork 535
Add Login component with Google authentication support #7107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Add_login_functionality_with_multiple_authentication_methods
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { THIRDWEB_CLIENT } from "@/lib/client"; | ||
import { getDomain } from "@/lib/constants"; | ||
import { SERVER_WALLET } from "@/lib/server-wallet"; | ||
|
||
import { Login } from "thirdweb"; | ||
|
||
export const { GET, POST } = Login.Server.toNextJsHandler( | ||
Login.Server.createAuthHandler({ | ||
client: THIRDWEB_CLIENT, | ||
domain: getDomain() ?? "", | ||
serverWallet: SERVER_WALLET, | ||
}), | ||
); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { CodeExample } from "@/components/code/code-example"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ThirdwebProvider from "@/components/thirdweb-provider"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { metadataBase } from "@/lib/constants"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import type { Metadata } from "next"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { PageLayout } from "../../../components/blocks/APIHeader"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { BasicLoginExample } from "../../../components/login/basic-example"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const metadata: Metadata = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
metadataBase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
title: "Login | thirdweb Connect", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "TODO", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default function Page() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<ThirdwebProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<PageLayout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
title="Login" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description={ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<>Let users login to your app using any authentication provider.</> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docsLink="https://portal.thirdweb.com/typescript/v5/auth?utm_source=playground" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="flex flex-col gap-14"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<CodeExample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lang="ts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
code={"TODO"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Spotted by Diamond |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
preview={<BasicLoginExample />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</PageLayout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</ThirdwebProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"use client"; | ||
|
||
import { THIRDWEB_CLIENT } from "@/lib/client"; | ||
import { useRef, useState } from "react"; | ||
import { Login } from "thirdweb"; | ||
import { sepolia } from "thirdweb/chains"; | ||
import { Button } from "../ui/button"; | ||
import { Input } from "../ui/input"; | ||
|
||
export function BasicLoginExample() { | ||
const [account, setAccount] = useState<Login.Client.LoginResult>(); | ||
const otpRef = useRef<HTMLInputElement>(null); | ||
|
||
if (!account) { | ||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<Button | ||
onClick={async () => { | ||
const account = await Login.Client.login({ | ||
type: "google", | ||
client: THIRDWEB_CLIENT, | ||
baseURL: `${window.location.origin}/connect/login/api/auth`, | ||
chain: sepolia, | ||
}); | ||
setAccount(account); | ||
}} | ||
> | ||
Login with Google | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
if (account.status === "requires_otp") { | ||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<Input ref={otpRef} placeholder="OTP" /> | ||
<Button | ||
onClick={async () => { | ||
if (!otpRef.current?.value) { | ||
return; | ||
} | ||
setAccount(await account.verifyOtp(otpRef.current?.value)); | ||
}} | ||
> | ||
Verify OTP | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<p>Logged in as: {account.id}</p> | ||
<Button | ||
onClick={async () => { | ||
const jwt = await account.getJWT(); | ||
alert(`JWT: ${jwt}`); | ||
}} | ||
> | ||
Get JWT | ||
</Button> | ||
<Button | ||
onClick={async () => { | ||
await account.logout(); | ||
setAccount(undefined); | ||
}} | ||
> | ||
Logout | ||
</Button> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "server-only"; | ||
import { Engine } from "thirdweb"; | ||
import { sepolia } from "thirdweb/chains"; | ||
import { THIRDWEB_CLIENT } from "./client"; | ||
|
||
const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string; | ||
const ENGINE_VAULT_ACCESS_TOKEN = process.env | ||
.ENGINE_VAULT_ACCESS_TOKEN as string; | ||
|
||
export const SERVER_WALLET = Engine.serverWallet({ | ||
address: BACKEND_WALLET_ADDRESS, | ||
client: THIRDWEB_CLIENT, | ||
vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN, | ||
chain: sepolia, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { login, type LoginOptions as LoginParams } from "./login.js"; | ||
export { login, type LoginOptions, type LoginResult } from "./login.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata description is currently set as
"TODO"
. This placeholder should be replaced with a meaningful description that accurately represents the Login page functionality. A good description will improve SEO and provide users with context about the page's purpose when shared on social media or in search results.Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.