Skip to content

Commit

Permalink
Show but disable unavailable auth methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Sep 10, 2024
1 parent 11a3e3e commit ff378fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions components/login-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LightningIcon from '@/svgs/bolt.svg'
import NostrIcon from '@/svgs/nostr.svg'
import Button from 'react-bootstrap/Button'

export default function LoginButton ({ text, type, className, onClick }) {
export default function LoginButton ({ text, type, className, onClick, disabled }) {
let Icon, variant
switch (type) {
case 'twitter':
Expand All @@ -29,7 +29,7 @@ export default function LoginButton ({ text, type, className, onClick }) {
const name = type.charAt(0).toUpperCase() + type.substr(1).toLowerCase()

return (
<Button className={className} variant={variant} onClick={onClick}>
<Button className={className} variant={variant} onClick={onClick} disabled={disabled}>
<Icon
width={20}
height={20} className='me-3'
Expand Down
43 changes: 31 additions & 12 deletions components/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { LightningAuthWithExplainer } from './lightning-auth'
import { NostrAuthWithExplainer } from './nostr-auth'
import LoginButton from './login-button'
import { emailSchema } from '@/lib/validate'
import { OverlayTrigger, Tooltip } from 'react-bootstrap'

export function EmailLoginForm ({ text, callbackUrl, multiAuth }) {
const disabled = multiAuth

return (
<Form
initial={{
Expand All @@ -26,8 +29,9 @@ export function EmailLoginForm ({ text, callbackUrl, multiAuth }) {
placeholder='[email protected]'
required
autoFocus
disabled={disabled}
/>
<SubmitButton variant='secondary' className={styles.providerButton}>{text || 'Login'} with Email</SubmitButton>
<SubmitButton disabled={disabled} variant='secondary' className={styles.providerButton}>{text || 'Login'} with Email</SubmitButton>
</Form>
)
}
Expand Down Expand Up @@ -74,10 +78,16 @@ export default function Login ({ providers, callbackUrl, multiAuth, error, text,
switch (provider.name) {
case 'Email':
return (
<div className='w-100' key={provider.id}>
<div className='mt-2 text-center text-muted fw-bold'>or</div>
<EmailLoginForm text={text} callbackUrl={callbackUrl} multiAuth={multiAuth} />
</div>
<OverlayTrigger
placement='bottom'
overlay={multiAuth ? <Tooltip>not available for account switching yet</Tooltip> : <></>}
trigger={['hover', 'focus']}
>
<div className='w-100' key={provider.id}>
<div className='mt-2 text-center text-muted fw-bold'>or</div>
<EmailLoginForm text={text} callbackUrl={callbackUrl} multiAuth={multiAuth} />
</div>
</OverlayTrigger>
)
case 'Lightning':
case 'Slashtags':
Expand All @@ -99,13 +109,22 @@ export default function Login ({ providers, callbackUrl, multiAuth, error, text,
)
default:
return (
<LoginButton
className={`mt-2 ${styles.providerButton}`}
key={provider.id}
type={provider.id.toLowerCase()}
onClick={() => signIn(provider.id, { callbackUrl, multiAuth })}
text={`${text || 'Login'} with`}
/>
<OverlayTrigger
placement='bottom'
overlay={multiAuth ? <Tooltip>not available for account switching yet</Tooltip> : <></>}
trigger={['hover', 'focus']}
>
<div className='w-100'>
<LoginButton
className={`mt-2 ${styles.providerButton}`}
key={provider.id}
type={provider.id.toLowerCase()}
onClick={() => signIn(provider.id, { callbackUrl, multiAuth })}
text={`${text || 'Login'} with`}
disabled={multiAuth}
/>
</div>
</OverlayTrigger>
)
}
})}
Expand Down
9 changes: 0 additions & 9 deletions pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ export async function getServerSideProps ({ req, res, query: { callbackUrl, mult
}

const providers = await getProviders()
if (multiAuth) {
// multi auth only supported for login with lightning and nostr
const multiAuthSupport = key => ['lightning', 'nostr'].includes(key)
Object.keys(providers).forEach(key => {
if (!multiAuthSupport(key)) {
delete providers[key]
}
})
}

return {
props: {
Expand Down

0 comments on commit ff378fb

Please sign in to comment.