mirror of
https://github.com/DocNR/POWR.git
synced 2025-04-22 16:51:33 +00:00
41 lines
822 B
TypeScript
41 lines
822 B
TypeScript
![]() |
// lib/hooks/useNDK.ts
|
||
|
import { useEffect } from 'react';
|
||
|
import { useNDKStore } from '../stores/ndk';
|
||
|
import type { NDKUser } from '@nostr-dev-kit/ndk';
|
||
|
|
||
|
export function useNDK() {
|
||
|
const { ndk, isLoading, init } = useNDKStore();
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (!ndk && !isLoading) {
|
||
|
init();
|
||
|
}
|
||
|
}, [ndk, isLoading, init]);
|
||
|
|
||
|
return { ndk, isLoading };
|
||
|
}
|
||
|
|
||
|
export function useNDKCurrentUser(): {
|
||
|
currentUser: NDKUser | null;
|
||
|
isAuthenticated: boolean;
|
||
|
isLoading: boolean;
|
||
|
} {
|
||
|
const { currentUser, isAuthenticated, isLoading } = useNDKStore();
|
||
|
|
||
|
return {
|
||
|
currentUser,
|
||
|
isAuthenticated,
|
||
|
isLoading
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function useNDKAuth() {
|
||
|
const { login, logout, isAuthenticated, isLoading } = useNDKStore();
|
||
|
|
||
|
return {
|
||
|
login,
|
||
|
logout,
|
||
|
isAuthenticated,
|
||
|
isLoading
|
||
|
};
|
||
|
}
|