From 7a4cb77aa347939091da8bf99607c1cd64b4a142 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 5 Oct 2025 23:32:52 +0100 Subject: [PATCH] refactor: remove dedicated login page, handle login through main UI --- src/App.tsx | 30 ++++---------------- src/components/Login.tsx | 60 ---------------------------------------- src/index.css | 48 -------------------------------- 3 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 src/components/Login.tsx diff --git a/src/App.tsx b/src/App.tsx index 7328d8e4..98ad36e0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react' -import { BrowserRouter, Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom' +import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faSpinner } from '@fortawesome/free-solid-svg-icons' import { EventStoreProvider, AccountsProvider, Hooks } from 'applesauce-react' @@ -8,7 +8,6 @@ import { AccountManager } from 'applesauce-accounts' import { registerCommonAccountTypes } from 'applesauce-accounts/accounts' import { RelayPool } from 'applesauce-relay' import { createAddressLoader } from 'applesauce-loaders/loaders' -import Login from './components/Login' import Bookmarks from './components/Bookmarks' import Toast from './components/Toast' import { useToast } from './hooks/useToast' @@ -16,19 +15,7 @@ import { useToast } from './hooks/useToast' const DEFAULT_ARTICLE = import.meta.env.VITE_DEFAULT_ARTICLE_NADDR || 'naddr1qvzqqqr4gupzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqqxnzd3cxqmrzv3exgmr2wfesgsmew' -// Protected route component that redirects to login if no active account -function ProtectedRoute({ children }: { children: React.ReactNode }) { - const activeAccount = Hooks.useActiveAccount() - const location = useLocation() - - if (!activeAccount) { - return - } - - return <>{children} -} - -// AppRoutes component that has access to navigation hooks +// AppRoutes component that has access to hooks function AppRoutes({ relayPool, showToast @@ -37,13 +24,11 @@ function AppRoutes({ showToast: (message: string) => void }) { const accountManager = Hooks.useAccountManager() - const navigate = useNavigate() const handleLogout = () => { accountManager.setActive(undefined as never) localStorage.removeItem('active') showToast('Logged out successfully') - navigate('/login') } return ( @@ -51,16 +36,13 @@ function AppRoutes({ - - + } /> } /> - showToast('Logged in successfully')} />} /> ) } diff --git a/src/components/Login.tsx b/src/components/Login.tsx deleted file mode 100644 index 5fba9992..00000000 --- a/src/components/Login.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import React, { useState } from 'react' -import { useNavigate, useLocation } from 'react-router-dom' -import { Hooks } from 'applesauce-react' -import { Accounts } from 'applesauce-accounts' - -interface LoginProps { - onLogin: () => void -} - -const Login: React.FC = ({ onLogin }) => { - const [isConnecting, setIsConnecting] = useState(false) - const accountManager = Hooks.useAccountManager() - const navigate = useNavigate() - const location = useLocation() - - const handleLogin = async () => { - try { - setIsConnecting(true) - - // Create account from nostr extension - const account = await Accounts.ExtensionAccount.fromExtension() - accountManager.addAccount(account) - accountManager.setActive(account) - onLogin() - - // Navigate back to where the user came from, or to the default article - const from = (location.state as { from?: { pathname: string } })?.from?.pathname - if (from) { - navigate(from, { replace: true }) - } else { - const defaultArticle = import.meta.env.VITE_DEFAULT_ARTICLE_NADDR || - 'naddr1qvzqqqr4gupzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqqxnzd3cxqmrzv3exgmr2wfesgsmew' - navigate(`/a/${defaultArticle}`) - } - } catch (error) { - console.error('Login failed:', error) - alert('Login failed. Please install a nostr browser extension and try again.') - } finally { - setIsConnecting(false) - } - } - - return ( -
-
-

Welcome to Boris

-

Connect your nostr account to view your bookmarks

- -
-
- ) -} - -export default Login diff --git a/src/index.css b/src/index.css index c6203b14..4a0c24e7 100644 --- a/src/index.css +++ b/src/index.css @@ -56,53 +56,6 @@ body { color: #888; } -/* Login Styles */ -.login-container { - display: flex; - justify-content: center; - align-items: center; - min-height: 50vh; -} - -.login-card { - background: #1a1a1a; - padding: 2rem; - border-radius: 8px; - border: 1px solid #333; - max-width: 400px; - width: 100%; -} - -.login-card h2 { - margin: 0 0 1rem 0; - color: #fff; -} - -.login-card p { - margin: 0 0 1.5rem 0; - color: #ccc; -} - -.login-button { - background: #646cff; - color: white; - border: none; - padding: 0.75rem 1.5rem; - border-radius: 4px; - font-size: 1rem; - cursor: pointer; - transition: background-color 0.2s; -} - -.login-button:hover:not(:disabled) { - background: #535bf2; -} - -.login-button:disabled { - opacity: 0.6; - cursor: not-allowed; -} - /* Bookmarks Styles */ .bookmarks-container { background: #1a1a1a; @@ -1147,7 +1100,6 @@ body { background-color: #ffffff; } - .login-card, .bookmark-item { background: #f9f9f9; border-color: #ddd;