import { useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { motion } from 'framer-motion' import toast from 'react-hot-toast' import { useAuthStore } from '../../store/authStore' import { BoltIcon, EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline' export default function Login() { const navigate = useNavigate() const { login, nostrLogin } = useAuthStore() const [isLoading, setIsLoading] = useState(false) const [isNostrLoading, setIsNostrLoading] = useState(false) const [showPassword, setShowPassword] = useState(false) const [formData, setFormData] = useState({ email: '', password: '', }) const handleSubmit = async (e) => { e.preventDefault() setIsLoading(true) try { await login(formData.email, formData.password) toast.success('Welcome back!') navigate('/dashboard') } catch (error) { toast.error(error.response?.data?.error || 'Failed to log in') } finally { setIsLoading(false) } } const handleNostrLogin = async () => { if (!window.nostr) { toast.error('No Nostr extension found. Please install Alby, nos2x, or another Nostr signer.') return } setIsNostrLoading(true) try { // Get public key from extension const pubkey = await window.nostr.getPublicKey() // Create a login event (kind 27235 is NIP-98 HTTP Auth) const event = { kind: 27235, created_at: Math.floor(Date.now() / 1000), tags: [ ['u', window.location.origin + '/api/auth/nostr/verify'], ['method', 'POST'], ], content: 'Login to LNPaywall', pubkey, } // Sign the event const signedEvent = await window.nostr.signEvent(event) // Send to backend await nostrLogin(pubkey, signedEvent) toast.success('Welcome back!') navigate('/dashboard') } catch (error) { console.error('Nostr login error:', error) toast.error(error.response?.data?.error || error.message || 'Failed to login with Nostr') } finally { setIsNostrLoading(false) } } const handleChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value }) } return (
Log in to your account
Don't have an account?{' '} Sign up