import { Button } from 'components/shared/Button'; import { ArrowRightCircleFilledIcon, GithubIcon, LinkIcon, LoaderIcon, QuestionMarkRoundFilledIcon, } from 'components/shared/CustomIcon'; import { GoogleIcon } from 'components/shared/CustomIcon/GoogleIcon'; import { DotBorder } from 'components/shared/DotBorder'; import { WavyBorder } from 'components/shared/WavyBorder'; import { useEffect, useState } from 'react'; import { CreatePasskey } from './CreatePasskey'; import { AppleIcon } from 'components/shared/CustomIcon/AppleIcon'; import { KeyIcon } from 'components/shared/CustomIcon/KeyIcon'; import { useToast } from 'components/shared/Toast'; import { Link } from 'react-router-dom'; import { PKPEthersWallet } from '@lit-protocol/pkp-ethers'; import { signInWithEthereum } from 'utils/siwe'; import { useSnowball } from 'utils/use-snowball'; type Provider = 'google' | 'github' | 'apple' | 'email' | 'passkey'; type Props = { onDone: () => void; }; export const Login = ({ onDone }: Props) => { const snowball = useSnowball(); const [error, setError] = useState(''); const [provider, setProvider] = useState(false); // const loading = snowball.auth.state.loading && provider; const loading = provider; const { toast } = useToast(); if (provider === 'email') { return ; } async function handleSigninRedirect() { let wallet: PKPEthersWallet | undefined; const { google } = snowball.auth; if (google.canHandleOAuthRedirectBack()) { setProvider('google'); console.log('Handling google redirect back'); try { await google.handleOAuthRedirectBack(); wallet = await google.getEthersWallet(); const result = await signInWithEthereum(1, 'login', wallet); if (result.error) { setError(result.error); setProvider(false); wallet = undefined; return; } } catch (err: any) { setError(err.message); console.log(err.message, err.name, err.details); setProvider(false); return; } } // if (apple.canHandleOAuthRedirectBack()) { // setProvider('apple'); // console.log('Handling apple redirect back'); // try { // await apple.handleOAuthRedirectBack(); // wallet = await apple.getEthersWallet(); // const result = await signInWithEthereum(1, 'login', wallet); // if (result.error) { // setError(result.error); // setProvider(false); // wallet = undefined; // return; // } // } catch (err: any) { // setError(err.message); // console.log(err.message, err.name, err.details); // setProvider(false); // return; // } // } if (wallet) { window.location.pathname = '/'; } } useEffect(() => { handleSigninRedirect(); }, []); return (
Sign in to Snowball
Got a Passkey?
Use it to sign in securely without using a password.
Lost your passkey?
OR
{error && (
Error: {error}
)}
Don't have an account?
Sign up now
); };