import React, { useState } from 'react' import { Hooks } from 'applesauce-react' import { Accounts } from 'applesauce-accounts' import { NostrConnectSigner } from 'applesauce-signers' import { getDefaultBunkerPermissions } from '../services/nostrConnect' const LoginOptions: React.FC = () => { const accountManager = Hooks.useAccountManager() const [showBunkerInput, setShowBunkerInput] = useState(false) const [bunkerUri, setBunkerUri] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const handleExtensionLogin = async () => { try { setIsLoading(true) setError(null) const account = await Accounts.ExtensionAccount.fromExtension() accountManager.addAccount(account) accountManager.setActive(account) } catch (err) { console.error('Extension login failed:', err) setError('Login failed. Please install a nostr browser extension and try again.') } finally { setIsLoading(false) } } const handleBunkerLogin = async () => { if (!bunkerUri.trim()) { setError('Please enter a bunker URI') return } if (!bunkerUri.startsWith('bunker://')) { setError('Invalid bunker URI. Must start with bunker://') return } try { setIsLoading(true) setError(null) // Create signer from bunker URI with default permissions const permissions = getDefaultBunkerPermissions() const signer = await NostrConnectSigner.fromBunkerURI(bunkerUri, { permissions }) // Get pubkey from signer const pubkey = await signer.getPublicKey() // Create account from signer const account = new Accounts.NostrConnectAccount(pubkey, signer) // Add to account manager and set active accountManager.addAccount(account) accountManager.setActive(account) // Clear input on success setBunkerUri('') setShowBunkerInput(false) } catch (err) { console.error('[bunker] Login failed:', err) const errorMessage = err instanceof Error ? err.message : 'Failed to connect to bunker' // Check for permission-related errors if (errorMessage.toLowerCase().includes('permission') || errorMessage.toLowerCase().includes('unauthorized')) { setError('Your bunker connection is missing signing permissions. Reconnect and approve signing.') } else { setError(errorMessage) } } finally { setIsLoading(false) } } return (

Login with:

{!showBunkerInput ? ( ) : (
setBunkerUri(e.target.value)} disabled={isLoading} style={{ padding: '0.75rem', fontSize: '0.9rem', width: '100%', boxSizing: 'border-box' }} onKeyDown={(e) => { if (e.key === 'Enter') { handleBunkerLogin() } }} />
)}
{error && (

{error}

)}

If you aren't on nostr yet, start here:{' '} nstart.me

) } export default LoginOptions