From a22040b705077810547e9c3abb0d37cd57d099af Mon Sep 17 00:00:00 2001 From: Michilis <120072772+Michilis@users.noreply.github.com> Date: Mon, 10 Feb 2025 04:40:31 +0100 Subject: [PATCH] Add files via upload --- README.md | 2 +- src/App.tsx | 47 +++++++++++++++++++++++++++++++++------------ src/pages/Login.tsx | 20 ++++++++++++++++++- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5ec817e..3e86475 100644 --- a/README.md +++ b/README.md @@ -164,4 +164,4 @@ For support, join our [Telegram group](https://t.me/noderunners) or visit [our w - Built by the Noderunners community - Powered by [strfry](https://github.com/hoytech/strfry) -- Lightning Network integration via [LNbits](https://lnbits.com) +- Lightning Network integration via [LNbits](https://lnbits.com) \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index a9d03b2..2aaca2c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; +import React, { useEffect } from 'react'; +import { BrowserRouter as Router, Routes, Route, useSearchParams, useNavigate } from 'react-router-dom'; import { Home } from './pages/Home'; import { Login } from './pages/Login'; import { Dashboard } from './pages/Dashboard'; @@ -7,20 +7,43 @@ import { Payment } from './pages/Payment'; import { ThankYou } from './pages/ThankYou'; import { Terms } from './pages/Terms'; import { Layout } from './components/Layout'; +import { useStore } from './store/useStore'; + +// Wrapper component to handle auto-login logic +function AutoLoginHandler({ children }: { children: React.ReactNode }) { + const [searchParams] = useSearchParams(); + const navigate = useNavigate(); + const { user, setUser } = useStore(); + + useEffect(() => { + const urlPubkey = searchParams.get('npub') || searchParams.get('pubkey'); + const isIframe = searchParams.get('iframe') === '1'; + + // Auto-login if pubkey/npub is in URL and user isn't already logged in + if (urlPubkey && !user) { + setUser({ pubkey: urlPubkey, isWhitelisted: false }); + navigate(isIframe ? '/dashboard?iframe=1' : '/dashboard'); + } + }, [searchParams, user, setUser, navigate]); + + return <>{children}; +} function App() { return ( - - }> - } /> - } /> - } /> - } /> - } /> - } /> - - + + + }> + } /> + } /> + } /> + } /> + } /> + } /> + + + ); } diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 9092510..c8e6918 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -10,12 +10,21 @@ export function Login() { const [isLoading, setIsLoading] = useState(false); const [pubkeyInput, setPubkeyInput] = useState(''); const isIframe = searchParams.get('iframe') === '1'; + const urlPubkey = searchParams.get('npub') || searchParams.get('pubkey'); useEffect(() => { + // Handle URL-based login + if (urlPubkey && !user) { + setUser({ pubkey: urlPubkey, isWhitelisted: false }); + navigate(isIframe ? '/dashboard?iframe=1' : '/dashboard'); + return; + } + + // Regular user redirect if (user) { navigate(isIframe ? '/dashboard?iframe=1' : '/dashboard'); } - }, [user, navigate, isIframe]); + }, [user, navigate, isIframe, urlPubkey, setUser]); const handleExtensionLogin = async () => { setIsLoading(true); @@ -73,6 +82,15 @@ export function Login() { } }; + // If we're processing URL-based login, show loading state + if (urlPubkey && !user) { + return ( +
+
+
+ ); + } + return (

Connect with Nostr