import { signIn } from 'next-auth/client' import Button from 'react-bootstrap/Button' import styles from './login.module.css' import GithubIcon from '../svgs/github-fill.svg' import TwitterIcon from '../svgs/twitter-fill.svg' import LightningIcon from '../svgs/bolt.svg' import { Form, Input, SubmitButton } from '../components/form' import * as Yup from 'yup' import { useEffect, useState } from 'react' import Alert from 'react-bootstrap/Alert' import LayoutCenter from '../components/layout-center' import { useRouter } from 'next/router' import LnQR, { LnQRSkeleton } from '../components/lnqr' import { gql, useMutation, useQuery } from '@apollo/client' export const EmailSchema = Yup.object({ email: Yup.string().email('email is no good').required('required') }) export default function Login ({ providers, callbackUrl, error, Header }) { const errors = { Signin: 'Try signing with a different account.', OAuthSignin: 'Try signing with a different account.', OAuthCallback: 'Try signing with a different account.', OAuthCreateAccount: 'Try signing with a different account.', EmailCreateAccount: 'Try signing with a different account.', Callback: 'Try signing with a different account.', OAuthAccountNotLinked: 'To confirm your identity, sign in with the same account you used originally.', EmailSignin: 'Check your email address.', CredentialsSignin: 'Lightning auth failed.', default: 'Unable to sign in.' } const [errorMessage, setErrorMessage] = useState(error && (errors[error] ?? errors.default)) const router = useRouter() return (
{Header &&
}
Not registered? Just login, we'll automatically create an account.
{errorMessage && setErrorMessage(undefined)} dismissible>{errorMessage}} {router.query.type === 'lightning' ? : ( <> {Object.values(providers).map(provider => { if (provider.name === 'Email' || provider.name === 'Lightning') { return null } const [variant, Icon] = provider.name === 'Twitter' ? ['twitter', TwitterIcon] : ['dark', GithubIcon] return ( ) })}
or
{ signIn('email', { email, callbackUrl }) }} > Login with Email
)}
) } function LnQRAuth ({ k1, encodedUrl, callbackUrl }) { const query = gql` { lnAuth(k1: "${k1}") { pubkey k1 } }` const { data } = useQuery(query, { pollInterval: 1000 }) if (data && data.lnAuth.pubkey) { signIn('credentials', { ...data.lnAuth, callbackUrl }) } // output pubkey and k1 return ( <> Does my wallet support lnurl-auth? ) } export function LightningAuth ({ callbackUrl }) { // query for challenge const [createAuth, { data, error }] = useMutation(gql` mutation createAuth { createAuth { k1 encodedUrl } }`) useEffect(createAuth, []) if (error) return
error
if (!data) { return } return }