further reducing google auth example
This commit is contained in:
		@@ -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>(Views.SIGN_IN);
 | 
			
		||||
  const [error, setError] = useState<any>();
 | 
			
		||||
 | 
			
		||||
  const [litAuthClient, setLitAuthClient] = useState<LitAuthClient>();
 | 
			
		||||
  const [litNodeClient, setLitNodeClient] = useState<LitNodeClient>();
 | 
			
		||||
  const [currentProviderType, setCurrentProviderType] =
 | 
			
		||||
    useState<ProviderType>();
 | 
			
		||||
  const [currentProviderType, setCurrentProviderType] = useState<ProviderType>();
 | 
			
		||||
  const [authMethod, setAuthMethod] = useState<AuthMethod>();
 | 
			
		||||
  const [pkps, setPKPs] = useState<IRelayPKP[]>([]);
 | 
			
		||||
  const [currentPKP, setCurrentPKP] = useState<IRelayPKP>();
 | 
			
		||||
  const [sessionSigs, setSessionSigs] = useState<SessionSigs>();
 | 
			
		||||
 | 
			
		||||
  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<GoogleProvider>(
 | 
			
		||||
      ProviderType.Google
 | 
			
		||||
    );
 | 
			
		||||
    const provider = litAuthClient.initProvider<GoogleProvider>(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 (
 | 
			
		||||
    <>
 | 
			
		||||
      <Head>
 | 
			
		||||
@@ -266,26 +244,7 @@ export default function Dashboard() {
 | 
			
		||||
        {view === Views.SIGN_IN && (
 | 
			
		||||
          <>
 | 
			
		||||
            <h1>Sign in with Lit</h1>
 | 
			
		||||
            {/* Since eth wallet is connected, prompt user to sign a message or disconnect their wallet */}
 | 
			
		||||
            <>
 | 
			
		||||
              {isConnected ? (
 | 
			
		||||
                <>
 | 
			
		||||
          
 | 
			
		||||
                  <button
 | 
			
		||||
                    onClick={async () => {
 | 
			
		||||
                      setError(null);
 | 
			
		||||
                      await disconnectAsync();
 | 
			
		||||
                    }}
 | 
			
		||||
                  >
 | 
			
		||||
                    Disconnect wallet
 | 
			
		||||
                  </button>
 | 
			
		||||
                </>
 | 
			
		||||
              ) : (
 | 
			
		||||
                <>
 | 
			
		||||
                  <button onClick={authWithGoogle}>Google</button>
 | 
			
		||||
                </>
 | 
			
		||||
              )}
 | 
			
		||||
            </>
 | 
			
		||||
              <button onClick={authWithGoogle}>Google</button>
 | 
			
		||||
          </>
 | 
			
		||||
        )}
 | 
			
		||||
 
 | 
			
		||||
@@ -340,12 +299,10 @@ export default function Dashboard() {
 | 
			
		||||
            <div>
 | 
			
		||||
              <p>Check out your PKP:</p>
 | 
			
		||||
              <p>{currentPKP.ethAddress}</p>
 | 
			
		||||
            </div>
 | 
			
		||||
            <hr></hr>
 | 
			
		||||
         
 | 
			
		||||
            </div>         
 | 
			
		||||
          </>
 | 
			
		||||
        )}
 | 
			
		||||
      </main>
 | 
			
		||||
    </>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user