Add files via upload
This commit is contained in:
@@ -164,4 +164,4 @@ For support, join our [Telegram group](https://t.me/noderunners) or visit [our w
|
|||||||
|
|
||||||
- Built by the Noderunners community
|
- Built by the Noderunners community
|
||||||
- Powered by [strfry](https://github.com/hoytech/strfry)
|
- Powered by [strfry](https://github.com/hoytech/strfry)
|
||||||
- Lightning Network integration via [LNbits](https://lnbits.com)
|
- Lightning Network integration via [LNbits](https://lnbits.com)
|
||||||
47
src/App.tsx
47
src/App.tsx
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
import { BrowserRouter as Router, Routes, Route, useSearchParams, useNavigate } from 'react-router-dom';
|
||||||
import { Home } from './pages/Home';
|
import { Home } from './pages/Home';
|
||||||
import { Login } from './pages/Login';
|
import { Login } from './pages/Login';
|
||||||
import { Dashboard } from './pages/Dashboard';
|
import { Dashboard } from './pages/Dashboard';
|
||||||
@@ -7,20 +7,43 @@ import { Payment } from './pages/Payment';
|
|||||||
import { ThankYou } from './pages/ThankYou';
|
import { ThankYou } from './pages/ThankYou';
|
||||||
import { Terms } from './pages/Terms';
|
import { Terms } from './pages/Terms';
|
||||||
import { Layout } from './components/Layout';
|
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() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
<Routes>
|
<AutoLoginHandler>
|
||||||
<Route path="/" element={<Layout />}>
|
<Routes>
|
||||||
<Route index element={<Home />} />
|
<Route path="/" element={<Layout />}>
|
||||||
<Route path="login" element={<Login />} />
|
<Route index element={<Home />} />
|
||||||
<Route path="dashboard" element={<Dashboard />} />
|
<Route path="login" element={<Login />} />
|
||||||
<Route path="payment" element={<Payment />} />
|
<Route path="dashboard" element={<Dashboard />} />
|
||||||
<Route path="thank-you" element={<ThankYou />} />
|
<Route path="payment" element={<Payment />} />
|
||||||
<Route path="terms" element={<Terms />} />
|
<Route path="thank-you" element={<ThankYou />} />
|
||||||
</Route>
|
<Route path="terms" element={<Terms />} />
|
||||||
</Routes>
|
</Route>
|
||||||
|
</Routes>
|
||||||
|
</AutoLoginHandler>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,21 @@ export function Login() {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [pubkeyInput, setPubkeyInput] = useState('');
|
const [pubkeyInput, setPubkeyInput] = useState('');
|
||||||
const isIframe = searchParams.get('iframe') === '1';
|
const isIframe = searchParams.get('iframe') === '1';
|
||||||
|
const urlPubkey = searchParams.get('npub') || searchParams.get('pubkey');
|
||||||
|
|
||||||
useEffect(() => {
|
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) {
|
if (user) {
|
||||||
navigate(isIframe ? '/dashboard?iframe=1' : '/dashboard');
|
navigate(isIframe ? '/dashboard?iframe=1' : '/dashboard');
|
||||||
}
|
}
|
||||||
}, [user, navigate, isIframe]);
|
}, [user, navigate, isIframe, urlPubkey, setUser]);
|
||||||
|
|
||||||
const handleExtensionLogin = async () => {
|
const handleExtensionLogin = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -73,6 +82,15 @@ export function Login() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If we're processing URL-based login, show loading state
|
||||||
|
if (urlPubkey && !user) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center min-h-[400px]">
|
||||||
|
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-orange-500"></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-md mx-auto bg-gray-800 rounded-lg p-8">
|
<div className="max-w-md mx-auto bg-gray-800 rounded-lg p-8">
|
||||||
<h1 className="text-2xl font-bold mb-6 text-center">Connect with Nostr</h1>
|
<h1 className="text-2xl font-bold mb-6 text-center">Connect with Nostr</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user