import { signIn } from 'next-auth/client' import styles from './login.module.css' import { Form, Input, SubmitButton } from '../components/form' import { useState } from 'react' import Alert from 'react-bootstrap/Alert' import { useRouter } from 'next/router' import { LightningAuthWithExplainer, SlashtagsAuth } from './lightning-auth' import LoginButton from './login-button' import { emailSchema } from '../lib/validate' export function EmailLoginForm ({ text, callbackUrl }) { return (
{ signIn('email', { email, callbackUrl }) }} > {text || 'Login'} with Email
) } export default function Login ({ providers, callbackUrl, error, text, Header, Footer }) { 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: 'Auth failed', default: 'Unable to sign in.' } const [errorMessage, setErrorMessage] = useState(error && (errors[error] ?? errors.default)) const router = useRouter() if (router.query.type === 'lightning') { return } if (router.query.type === 'slashtags') { return } return (
{Header &&
} {errorMessage && setErrorMessage(undefined)} dismissible >{errorMessage} } {providers && Object.values(providers).map(provider => { switch (provider.name) { case 'Email': return (
or
) case 'Lightning': case 'Slashtags': return ( router.push({ pathname: router.pathname, query: { callbackUrl: router.query.callbackUrl, type: provider.name.toLowerCase() } })} text={`${text || 'Login'} with`} /> ) default: return ( signIn(provider.id, { callbackUrl })} text={`${text || 'Login'} with`} /> ) } })} {Footer &&
) }