From 8d9980c59e26fe5d6705ae41474db837ff728db0 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Fri, 21 Jul 2023 10:11:29 +0200 Subject: [PATCH] further reducing google auth example --- example/google-auth/src/pages/index.tsx | 59 ++++--------------------- 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/example/google-auth/src/pages/index.tsx b/example/google-auth/src/pages/index.tsx index 6b3f272..2fd41c5 100644 --- a/example/google-auth/src/pages/index.tsx +++ b/example/google-auth/src/pages/index.tsx @@ -12,9 +12,6 @@ import { IRelayPKP, AuthMethod, SessionSigs } from '@lit-protocol/types'; import { ProviderType } from '@lit-protocol/constants'; import { useRouter } from 'next/router'; import {LitAccessControlConditionResource, LitAbility} from '@lit-protocol/auth-helpers'; -import { useConnect, useAccount, useDisconnect, Connector } from 'wagmi'; - - enum Views { SIGN_IN = 'sign_in', @@ -29,49 +26,31 @@ enum Views { ERROR = 'error', } - export default function Dashboard() { const redirectUri = 'http://localhost:3000'; - const router = useRouter(); - + const [view, setView] = useState(Views.SIGN_IN); const [error, setError] = useState(); - const [litAuthClient, setLitAuthClient] = useState(); const [litNodeClient, setLitNodeClient] = useState(); - const [currentProviderType, setCurrentProviderType] = - useState(); + const [currentProviderType, setCurrentProviderType] = useState(); const [authMethod, setAuthMethod] = useState(); const [pkps, setPKPs] = useState([]); const [currentPKP, setCurrentPKP] = useState(); const [sessionSigs, setSessionSigs] = useState(); - const { connectAsync, connectors } = useConnect({ - onError(error) { - console.error(error); - setError(error); - }, - }); - const { isConnected, connector, address } = useAccount(); - const { disconnectAsync } = useDisconnect(); - - /** - * Begin auth flow with Google - */ async function authWithGoogle() { setCurrentProviderType(ProviderType.Google); - const provider = litAuthClient.initProvider( - ProviderType.Google - ); + const provider = litAuthClient.initProvider(ProviderType.Google); await provider.signIn(); } + /** * Handle redirect from Lit login server */ - const handleRedirect = useCallback( - async (providerName: string) => { + const handleRedirect = useCallback(async (providerName: string) => { setView(Views.HANDLE_REDIRECT); try { // Get relevant provider @@ -228,7 +207,6 @@ export default function Dashboard() { if (!litNodeClient) { return null; } - return ( <> @@ -266,26 +244,7 @@ export default function Dashboard() { {view === Views.SIGN_IN && ( <>

Sign in with Lit

- {/* Since eth wallet is connected, prompt user to sign a message or disconnect their wallet */} - <> - {isConnected ? ( - <> - - - - ) : ( - <> - - - )} - + )} @@ -340,12 +299,10 @@ export default function Dashboard() {

Check out your PKP:

{currentPKP.ethAddress}

-
-
- + )} ); -} +} \ No newline at end of file