story-research-zapwall/hooks/useNostrAuth.ts
Nicolas Cantu cb7ee0cfd4 Replace nos2x and NostrConnect with Alby authentication
- Remove nos2x and NostrConnect support
- Create new NostrAuthService using Alby (window.nostr NIP-07)
- Replace useNostrConnect with useNostrAuth in all components
- Update NostrRemoteSigner to use Alby for signing
- Delete NostrConnect-related files (nostrconnect.ts, handlers, etc.)
- Update documentation to reflect Alby-only authentication
- Remove NOSTRCONNECT_BRIDGE environment variable
- All TypeScript checks pass
2025-12-27 23:54:34 +01:00

50 lines
1.1 KiB
TypeScript

import { useState, useEffect } from 'react'
import { nostrAuthService } from '@/lib/nostrAuth'
import type { NostrConnectState } from '@/types/nostr'
export function useNostrAuth() {
const [state, setState] = useState<NostrConnectState>(nostrAuthService.getState())
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
const unsubscribe = nostrAuthService.subscribe((newState) => {
setState(newState)
})
return unsubscribe
}, [])
const connect = async () => {
setLoading(true)
setError(null)
try {
await nostrAuthService.connect()
} catch (e) {
setError(e instanceof Error ? e.message : 'Connection failed')
} finally {
setLoading(false)
}
}
const disconnect = async () => {
setLoading(true)
try {
nostrAuthService.disconnect()
} catch (e) {
setError(e instanceof Error ? e.message : 'Disconnection failed')
} finally {
setLoading(false)
}
}
return {
...state,
loading,
error,
connect,
disconnect,
}
}