diff --git a/bun.lockb b/bun.lockb index 63d42df..7ee5bf0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/Modals/Login.tsx b/components/Modals/Login.tsx index 604fb84..f02ffc1 100644 --- a/components/Modals/Login.tsx +++ b/components/Modals/Login.tsx @@ -7,11 +7,14 @@ import { nip19 } from "nostr-tools"; // import { useKeys } from "@/app/_providers/keysProvider"; import { useNDK } from "@/app/_providers/ndk"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; export default function LoginModal() { - const { loginWithNip07 } = useNDK(); + const { loginWithNip07, loginWithSecret } = useNDK(); const { loginWithPubkey, currentUser } = useCurrentUser(); const [isLoading, setIsLoading] = useState(false); + const [nsec, setNsec] = useState(""); const modal = useModal(); useEffect(() => { @@ -79,6 +82,26 @@ export default function LoginModal() { setIsLoading(false); modal?.hide(); } + async function handleLoginNsec() { + setIsLoading(true); + console.log("loging in "); + if (typeof window.nostr !== "undefined") { + const user = await loginWithSecret(nsec); + if (!user) { + throw new Error("NO auth"); + } + console.log("LOGIN", user); + await loginWithPubkey(nip19.decode(user.npub).data.toString()); + localStorage.setItem("shouldReconnect", "true"); + } + + if (typeof window.webln !== "undefined") { + await window.webln.enable(); + } + console.log("connected "); + setIsLoading(false); + modal?.hide(); + } return ( ); diff --git a/lib/hooks/useCurrentUser.ts b/lib/hooks/useCurrentUser.ts index d5a172a..f6f43a5 100644 --- a/lib/hooks/useCurrentUser.ts +++ b/lib/hooks/useCurrentUser.ts @@ -8,7 +8,9 @@ import { nip19 } from "nostr-tools"; import useLists from "./useLists"; import useSubscriptions from "./useSubscriptions"; import { db } from "@nostr-dev-kit/ndk-cache-dexie"; -import { unixTimeNowInSeconds } from "../nostr/dates"; +import { webln } from "@getalby/sdk"; +const loadNWCUrl = ""; +const nwc = new webln.NWC({ nostrWalletConnectUrl: loadNWCUrl }); export default function useCurrentUser() { const { @@ -19,7 +21,8 @@ export default function useCurrentUser() { setFollows, addFollow, } = currentUserStore(); - const { loginWithNip07, getProfile, ndk, fetchEvents } = useNDK(); + const { loginWithNip07, loginWithNip46, getProfile, ndk, fetchEvents } = + useNDK(); const { init } = useLists(); const { init: initSubscriptions, mySubscription } = useSubscriptions(); diff --git a/package.json b/package.json index 08660ea..cee7a7d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@blocknote/core": "^0.9.5", "@blocknote/react": "^0.9.5", + "@getalby/sdk": "^2.5.0", "@hookform/resolvers": "^3.3.2", "@noble/hashes": "^1.3.2", "@nostr-dev-kit/ndk": "^2.0.0",