story-research-zapwall/hooks/useNostrAuth.ts
Nicolas Cantu 398b9506e6 Remove duplicate title and description from presentation page
- Remove title and description from pages/presentation.tsx
- Keep title with user name in AuthorPresentationEditor form
- Fix duplicate display issue
2025-12-27 23:56:31 +01:00

49 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,
}
}