mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Add nostrconnect:// QR code login for NIP-46 remote signers
Adds the client-initiated NIP-46 flow alongside the existing bunker:// paste input. Desktop users scan a generated QR code with their signer app (Amber, nsec.app, etc.); mobile users get an "Open signer app" deep-link plus a /remoteloginsuccess callback page. The pasted bunker:// URI moves into a collapsible fallback below the QR. A shared BunkerLoginPanel component owns the session lifecycle and is embedded in both LoginDialog and SimpleLoginDialog. The listener effect depends only on a sessionToken and reads login/onLoggedIn/config through refs so parent re-renders don't tear down an in-flight handshake. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This commit is contained in:
1 parent
0da339c214
commit
0013ece013
7 files changed
+388
-134
No files matched your search
Generated
+27
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "shakespeare.diy",
|
||||
"version": "9.13.1",
|
||||
"version": "9.13.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "shakespeare.diy",
|
||||
"version": "9.13.1",
|
||||
"version": "9.13.2",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@capacitor/app": "^8.1.0",
|
||||
@@ -5003,6 +5003,7 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5016,6 +5017,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5029,6 +5031,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5042,6 +5045,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5055,6 +5059,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5068,6 +5073,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5081,6 +5087,7 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5094,6 +5101,7 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5107,6 +5115,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5120,6 +5129,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5133,6 +5143,7 @@
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5146,6 +5157,7 @@
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5159,6 +5171,7 @@
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5172,6 +5185,7 @@
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5185,6 +5199,7 @@
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5198,6 +5213,7 @@
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5211,6 +5227,7 @@
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5224,6 +5241,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5237,6 +5255,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5250,6 +5269,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5263,6 +5283,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5276,6 +5297,7 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5289,6 +5311,7 @@
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5302,6 +5325,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -5315,6 +5339,7 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
|
||||
@@ -21,6 +21,7 @@ import GitHubOAuth from "./pages/GitHubOAuth";
|
||||
import NetlifyOAuth from "./pages/NetlifyOAuth";
|
||||
import VercelOAuth from "./pages/VercelOAuth";
|
||||
import OpenRouterOAuth from "./pages/OpenRouterOAuth";
|
||||
import RemoteLoginSuccess from "./pages/RemoteLoginSuccess";
|
||||
import { NIP19Page } from "./pages/NIP19Page";
|
||||
import NotFound from "./pages/NotFound";
|
||||
import { ProjectView } from "./pages/ProjectView";
|
||||
@@ -43,6 +44,7 @@ export function AppRouter() {
|
||||
<Route path="/oauth/netlify" element={<NetlifyOAuth />} />
|
||||
<Route path="/oauth/vercel" element={<VercelOAuth />} />
|
||||
<Route path="/oauth/openrouter" element={<OpenRouterOAuth />} />
|
||||
<Route path="/remoteloginsuccess" element={<RemoteLoginSuccess />} />
|
||||
<Route path="/settings" element={<SettingsLayout />}>
|
||||
<Route index element={<Settings />} />
|
||||
<Route path="preferences" element={<Preferences />} />
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import QRCode from 'qrcode';
|
||||
import { ChevronDown, ChevronUp, ExternalLink, Loader2 } from 'lucide-react';
|
||||
import {
|
||||
generateNostrConnectParams,
|
||||
generateNostrConnectURI,
|
||||
type NostrConnectParams,
|
||||
} from '@nostrify/react/login';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleContent,
|
||||
CollapsibleTrigger,
|
||||
} from '@/components/ui/collapsible';
|
||||
import { useLoginActions } from '@/hooks/useLoginActions';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
interface BunkerLoginPanelProps {
|
||||
/** Called after a successful login (either nostrconnect or pasted bunker URI). */
|
||||
onLoggedIn: () => void;
|
||||
}
|
||||
|
||||
const validateBunkerUri = (uri: string) => uri.startsWith('bunker://');
|
||||
|
||||
// UA-based mobile check. Distinct from the viewport-based `useIsMobile` —
|
||||
// here we care whether the platform can deep-link into a signer app, not
|
||||
// whether the window is narrow.
|
||||
const isMobileDevice = (): boolean => {
|
||||
if (typeof navigator === 'undefined') return false;
|
||||
return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Shared NIP-46 login panel: presents a `nostrconnect://` QR code (desktop)
|
||||
* or an "Open signer app" deep-link (mobile) as the primary path, with the
|
||||
* legacy `bunker://` paste input as a collapsible fallback.
|
||||
*
|
||||
* Mount/unmount drives the session lifecycle — when the parent's tab is
|
||||
* inactive the panel is unmounted, which aborts the listener and clears
|
||||
* state. Switching back generates a fresh session.
|
||||
*/
|
||||
export const BunkerLoginPanel: React.FC<BunkerLoginPanelProps> = ({ onLoggedIn }) => {
|
||||
const login = useLoginActions();
|
||||
const { config } = useAppContext();
|
||||
|
||||
const [sessionToken, setSessionToken] = useState(0);
|
||||
const [nostrConnectUri, setNostrConnectUri] = useState('');
|
||||
const [qrDataUrl, setQrDataUrl] = useState('');
|
||||
const [connectError, setConnectError] = useState<string | null>(null);
|
||||
const [hasOpenedSigner, setHasOpenedSigner] = useState(false);
|
||||
const [showBunkerInput, setShowBunkerInput] = useState(false);
|
||||
const [bunkerUri, setBunkerUri] = useState('');
|
||||
const [bunkerError, setBunkerError] = useState<string | null>(null);
|
||||
const [isBunkerLoggingIn, setIsBunkerLoggingIn] = useState(false);
|
||||
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
// Refs so the listener effect can read the latest values without
|
||||
// re-running on every parent re-render. gm-protocol documents the trap:
|
||||
// a stale closure mid-handshake silently drops the signer's response.
|
||||
// `config` is rebuilt every render by AppProvider, so we must NOT
|
||||
// depend on it in the effect's dep array — otherwise the in-flight
|
||||
// subscription is torn down on each parent render.
|
||||
const loginRef = useRef(login);
|
||||
const onLoggedInRef = useRef(onLoggedIn);
|
||||
const configRef = useRef(config);
|
||||
|
||||
useEffect(() => {
|
||||
loginRef.current = login;
|
||||
onLoggedInRef.current = onLoggedIn;
|
||||
configRef.current = config;
|
||||
});
|
||||
|
||||
const isMobile = isMobileDevice();
|
||||
|
||||
// Generate a session and start listening for the signer. Driven by
|
||||
// `sessionToken` so a "Try again" can force a fresh session deterministically.
|
||||
// Intentionally has only `sessionToken` in its deps — see comment on the
|
||||
// refs above for why.
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const controller = new AbortController();
|
||||
abortControllerRef.current?.abort();
|
||||
abortControllerRef.current = controller;
|
||||
|
||||
const run = async () => {
|
||||
const relayUrls = (configRef.current.relayMetadata?.relays ?? [])
|
||||
.filter((r) => r.write !== false)
|
||||
.map((r) => r.url);
|
||||
|
||||
if (relayUrls.length === 0) {
|
||||
if (!cancelled) {
|
||||
setConnectError(
|
||||
'No relays configured. Add a relay in settings to use this login method.',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const params: NostrConnectParams = generateNostrConnectParams(relayUrls);
|
||||
const uri = generateNostrConnectURI(params, {
|
||||
name: 'Shakespeare',
|
||||
callback: isMobileDevice()
|
||||
? `${window.location.origin}/remoteloginsuccess`
|
||||
: undefined,
|
||||
});
|
||||
|
||||
try {
|
||||
const dataUrl = await QRCode.toDataURL(uri, {
|
||||
width: 400,
|
||||
margin: 2,
|
||||
color: { dark: '#000000', light: '#FFFFFF' },
|
||||
});
|
||||
if (cancelled) return;
|
||||
setQrDataUrl(dataUrl);
|
||||
} catch (e) {
|
||||
console.error('Failed to render nostrconnect QR:', e);
|
||||
}
|
||||
|
||||
if (cancelled) return;
|
||||
setNostrConnectUri(uri);
|
||||
setConnectError(null);
|
||||
|
||||
try {
|
||||
await loginRef.current.nostrconnect(params, controller.signal);
|
||||
if (cancelled || controller.signal.aborted) return;
|
||||
onLoggedInRef.current();
|
||||
} catch (error) {
|
||||
if (cancelled || controller.signal.aborted) return;
|
||||
if (error instanceof Error && error.name === 'AbortError') return;
|
||||
console.error('nostrconnect failed:', error);
|
||||
setConnectError(
|
||||
error instanceof Error ? error.message : 'Failed to connect to signer.',
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
void run();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
controller.abort();
|
||||
};
|
||||
// Intentional: deps limited to `sessionToken` so parent re-renders
|
||||
// don't tear down the in-flight subscription. Config + login are read
|
||||
// via refs that are updated each render.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [sessionToken]);
|
||||
|
||||
const handleConnectRetry = useCallback(() => {
|
||||
setNostrConnectUri('');
|
||||
setQrDataUrl('');
|
||||
setConnectError(null);
|
||||
setHasOpenedSigner(false);
|
||||
setSessionToken((t) => t + 1);
|
||||
}, []);
|
||||
|
||||
const handleOpenSignerApp = () => {
|
||||
if (!nostrConnectUri) return;
|
||||
// Flip into the waiting view *before* navigating so the user sees
|
||||
// feedback the moment they return from the signer app.
|
||||
setHasOpenedSigner(true);
|
||||
window.location.href = nostrConnectUri;
|
||||
};
|
||||
|
||||
const handleBunkerLogin = async () => {
|
||||
if (!bunkerUri.trim()) {
|
||||
setBunkerError('Please enter a bunker URI');
|
||||
return;
|
||||
}
|
||||
if (!validateBunkerUri(bunkerUri)) {
|
||||
setBunkerError('Invalid bunker URI format. Must start with bunker://');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsBunkerLoggingIn(true);
|
||||
setBunkerError(null);
|
||||
try {
|
||||
await login.bunker(bunkerUri);
|
||||
onLoggedIn();
|
||||
} catch {
|
||||
setBunkerError('Failed to connect to bunker. Please check the URI.');
|
||||
} finally {
|
||||
setIsBunkerLoggingIn(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Mobile: flip to waiting view once the user taps "Open signer app" so
|
||||
// the return trip shows progress, not the original button. Desktop:
|
||||
// keep the QR scannable (no per-phase progress in @nostrify/react v0.4.1).
|
||||
const showWaitingView = isMobile && hasOpenedSigner && !connectError;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col items-center space-y-4">
|
||||
{connectError ? (
|
||||
<div className="flex flex-col items-center space-y-3 py-4 w-full">
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>{connectError}</AlertDescription>
|
||||
</Alert>
|
||||
<Button variant="outline" onClick={handleConnectRetry}>
|
||||
Try again
|
||||
</Button>
|
||||
</div>
|
||||
) : showWaitingView ? (
|
||||
<div className="flex flex-col items-center space-y-4 py-6 w-full">
|
||||
<Loader2 className="w-8 h-8 animate-spin text-primary" />
|
||||
<p className="text-sm text-muted-foreground text-center">
|
||||
Waiting for signer…
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleConnectRetry}
|
||||
className="text-sm text-primary hover:underline underline-offset-4 font-medium"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
) : nostrConnectUri && qrDataUrl ? (
|
||||
<>
|
||||
{!isMobile && (
|
||||
<>
|
||||
<div className="p-3 bg-white rounded-xl">
|
||||
<img
|
||||
src={qrDataUrl}
|
||||
alt="nostrconnect QR code"
|
||||
width={200}
|
||||
height={200}
|
||||
className="block"
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground text-center max-w-[260px]">
|
||||
Scan this QR code with your Nostr signer app to log in.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isMobile && (
|
||||
<Button onClick={handleOpenSignerApp} className="w-full h-12">
|
||||
<ExternalLink className="w-5 h-5 mr-2" />
|
||||
Open signer app
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-[200px]">
|
||||
<Loader2 className="w-8 h-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Collapsible open={showBunkerInput} onOpenChange={setShowBunkerInput}>
|
||||
<CollapsibleTrigger className="w-full flex items-center justify-center gap-1 text-sm text-muted-foreground hover:text-foreground py-2">
|
||||
<span>Enter bunker URI manually</span>
|
||||
{showBunkerInput ? (
|
||||
<ChevronUp className="w-4 h-4" />
|
||||
) : (
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
)}
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent className="space-y-3 pt-2">
|
||||
<Input
|
||||
value={bunkerUri}
|
||||
onChange={(e) => {
|
||||
setBunkerUri(e.target.value);
|
||||
if (bunkerError) setBunkerError(null);
|
||||
}}
|
||||
placeholder="bunker://"
|
||||
className={bunkerError ? 'border-red-500' : ''}
|
||||
autoComplete="off"
|
||||
/>
|
||||
{bunkerError && (
|
||||
<p className="text-sm text-red-500">{bunkerError}</p>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleBunkerLogin}
|
||||
disabled={isBunkerLoggingIn || !bunkerUri.trim()}
|
||||
className="w-full"
|
||||
>
|
||||
{isBunkerLoggingIn ? 'Connecting...' : 'Connect with bunker URI'}
|
||||
</Button>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BunkerLoginPanel;
|
||||
@@ -10,6 +10,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { useLoginActions } from '@/hooks/useLoginActions';
|
||||
import { cn } from '@/lib/utils';
|
||||
import BunkerLoginPanel from '@/components/auth/BunkerLoginPanel';
|
||||
|
||||
interface LoginDialogProps {
|
||||
isOpen: boolean;
|
||||
@@ -22,18 +23,12 @@ const validateNsec = (nsec: string) => {
|
||||
return /^nsec1[a-zA-Z0-9]{58}$/.test(nsec);
|
||||
};
|
||||
|
||||
const validateBunkerUri = (uri: string) => {
|
||||
return uri.startsWith('bunker://');
|
||||
};
|
||||
|
||||
const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin, onSignup }) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isFileLoading, setIsFileLoading] = useState(false);
|
||||
const [nsec, setNsec] = useState('');
|
||||
const [bunkerUri, setBunkerUri] = useState('');
|
||||
const [errors, setErrors] = useState<{
|
||||
nsec?: string;
|
||||
bunker?: string;
|
||||
file?: string;
|
||||
extension?: string;
|
||||
}>({});
|
||||
@@ -47,7 +42,6 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin, onS
|
||||
setIsLoading(false);
|
||||
setIsFileLoading(false);
|
||||
setNsec('');
|
||||
setBunkerUri('');
|
||||
setErrors({});
|
||||
// Reset file input
|
||||
if (fileInputRef.current) {
|
||||
@@ -111,36 +105,6 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin, onS
|
||||
executeLogin(nsec);
|
||||
};
|
||||
|
||||
const handleBunkerLogin = async () => {
|
||||
if (!bunkerUri.trim()) {
|
||||
setErrors(prev => ({ ...prev, bunker: 'Please enter a bunker URI' }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateBunkerUri(bunkerUri)) {
|
||||
setErrors(prev => ({ ...prev, bunker: 'Invalid bunker URI format. Must start with bunker://' }));
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
setErrors(prev => ({ ...prev, bunker: undefined }));
|
||||
|
||||
try {
|
||||
await login.bunker(bunkerUri);
|
||||
onLogin();
|
||||
onClose();
|
||||
// Clear the URI from memory
|
||||
setBunkerUri('');
|
||||
} catch {
|
||||
setErrors(prev => ({
|
||||
...prev,
|
||||
bunker: 'Failed to connect to bunker. Please check the URI.'
|
||||
}));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
@@ -333,38 +297,13 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin, onS
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='bunker' className='space-y-3 bg-muted'>
|
||||
<div className='space-y-2'>
|
||||
<label htmlFor='bunkerUri' className='text-sm font-medium text-gray-700 dark:text-gray-400'>
|
||||
Bunker URI
|
||||
</label>
|
||||
<Input
|
||||
id='bunkerUri'
|
||||
value={bunkerUri}
|
||||
onChange={(e) => {
|
||||
setBunkerUri(e.target.value);
|
||||
if (errors.bunker) setErrors(prev => ({ ...prev, bunker: undefined }));
|
||||
}}
|
||||
className={`rounded-lg border-gray-300 dark:border-gray-700 focus-visible:ring-primary ${
|
||||
errors.bunker ? 'border-red-500' : ''
|
||||
}`}
|
||||
placeholder='bunker://'
|
||||
autoComplete="off"
|
||||
/>
|
||||
{errors.bunker && (
|
||||
<p className="text-sm text-red-500">{errors.bunker}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
className='w-full rounded-full py-4'
|
||||
onClick={handleBunkerLogin}
|
||||
disabled={isLoading || !bunkerUri.trim()}
|
||||
>
|
||||
{isLoading ? 'Connecting...' : 'Login with Bunker'}
|
||||
</Button>
|
||||
</div>
|
||||
<TabsContent value='bunker' className='space-y-3'>
|
||||
<BunkerLoginPanel
|
||||
onLoggedIn={() => {
|
||||
onLogin();
|
||||
onClose();
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Cloud, Upload } from 'lucide-react';
|
||||
import { Upload } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
// Alert components removed as they're not used in the simplified design
|
||||
import { useLoginActions } from '@/hooks/useLoginActions';
|
||||
import { cn } from '@/lib/utils';
|
||||
import BunkerLoginPanel from '@/components/auth/BunkerLoginPanel';
|
||||
|
||||
// Only using key-add step now
|
||||
|
||||
@@ -20,10 +21,6 @@ const validateNsec = (nsec: string) => {
|
||||
return /^nsec1[a-zA-Z0-9]{58}$/.test(nsec);
|
||||
};
|
||||
|
||||
const validateBunkerUri = (uri: string) => {
|
||||
return uri.startsWith('bunker://');
|
||||
};
|
||||
|
||||
const SimpleLoginDialog: React.FC<SimpleLoginDialogProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
@@ -34,11 +31,9 @@ const SimpleLoginDialog: React.FC<SimpleLoginDialogProps> = ({
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isFileLoading, setIsFileLoading] = useState(false);
|
||||
const [nsec, setNsec] = useState('');
|
||||
const [bunkerUri, setBunkerUri] = useState('');
|
||||
const [activeTab, setActiveTab] = useState<'nsec' | 'bunker'>('nsec');
|
||||
const [errors, setErrors] = useState<{
|
||||
nsec?: string;
|
||||
bunker?: string;
|
||||
extension?: string;
|
||||
file?: string;
|
||||
}>({});
|
||||
@@ -52,7 +47,6 @@ const SimpleLoginDialog: React.FC<SimpleLoginDialogProps> = ({
|
||||
setIsLoading(false);
|
||||
setIsFileLoading(false);
|
||||
setNsec('');
|
||||
setBunkerUri('');
|
||||
setActiveTab('nsec');
|
||||
setErrors({});
|
||||
// Reset file input
|
||||
@@ -97,35 +91,6 @@ const SimpleLoginDialog: React.FC<SimpleLoginDialogProps> = ({
|
||||
executeLogin(nsec);
|
||||
};
|
||||
|
||||
const handleBunkerLogin = async () => {
|
||||
if (!bunkerUri.trim()) {
|
||||
setErrors(prev => ({ ...prev, bunker: 'Please enter a bunker URI' }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateBunkerUri(bunkerUri)) {
|
||||
setErrors(prev => ({ ...prev, bunker: 'Invalid bunker URI format. Must start with bunker://' }));
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
setErrors(prev => ({ ...prev, bunker: undefined }));
|
||||
|
||||
try {
|
||||
await login.bunker(bunkerUri);
|
||||
onLogin();
|
||||
onClose();
|
||||
setBunkerUri('');
|
||||
} catch {
|
||||
setErrors(prev => ({
|
||||
...prev,
|
||||
bunker: 'Failed to connect to bunker. Please check the URI.'
|
||||
}));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const executeLogin = (key: string) => {
|
||||
setIsLoading(true);
|
||||
setErrors({});
|
||||
@@ -278,32 +243,12 @@ const SimpleLoginDialog: React.FC<SimpleLoginDialogProps> = ({
|
||||
)}
|
||||
|
||||
{activeTab === 'bunker' && (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
value={bunkerUri}
|
||||
onChange={(e) => {
|
||||
setBunkerUri(e.target.value);
|
||||
if (errors.bunker) setErrors(prev => ({ ...prev, bunker: undefined }));
|
||||
}}
|
||||
placeholder="bunker://"
|
||||
className={errors.bunker ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.bunker && (
|
||||
<p className="text-sm text-red-500">{errors.bunker}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
size="lg"
|
||||
onClick={handleBunkerLogin}
|
||||
disabled={isLoading || !bunkerUri.trim()}
|
||||
className="w-full"
|
||||
>
|
||||
<Cloud className="w-4 h-4 mr-2" />
|
||||
{isLoading ? 'Connecting...' : 'Connect'}
|
||||
</Button>
|
||||
</div>
|
||||
<BunkerLoginPanel
|
||||
onLoggedIn={() => {
|
||||
onLogin();
|
||||
onClose();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="relative">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { NLogin, useNostrLogin } from '@nostrify/react/login';
|
||||
import type { NostrConnectParams } from '@nostrify/react/login';
|
||||
|
||||
// NOTE: This file should not be edited except for adding new login methods.
|
||||
|
||||
@@ -18,6 +19,14 @@ export function useLoginActions() {
|
||||
const login = await NLogin.fromBunker(uri, nostr);
|
||||
addLogin(login);
|
||||
},
|
||||
// Login via client-initiated NIP-46 ("nostrconnect://" QR code).
|
||||
// Caller generates params with `generateNostrConnectParams`, renders the
|
||||
// URI as a QR/deep-link, and awaits this promise — it resolves when the
|
||||
// remote signer connects back over the relay.
|
||||
async nostrconnect(params: NostrConnectParams, signal?: AbortSignal): Promise<void> {
|
||||
const login = await NLogin.fromNostrConnect(params, nostr, { signal });
|
||||
addLogin(login);
|
||||
},
|
||||
// Login with a NIP-07 browser extension
|
||||
async extension(): Promise<void> {
|
||||
const login = await NLogin.fromExtension();
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useSeoMeta } from "@unhead/react";
|
||||
import { useEffect } from "react";
|
||||
import { CheckCircle2 } from "lucide-react";
|
||||
|
||||
// Callback target for mobile NIP-46 signer apps after they approve a
|
||||
// `nostrconnect://` request. The actual login completes via the relay
|
||||
// subscription in the original tab — this page just provides a friendly
|
||||
// landing if the signer opened it in a new tab/window.
|
||||
const RemoteLoginSuccess = () => {
|
||||
useSeoMeta({
|
||||
title: "Signer connected",
|
||||
description: "You can return to Shakespeare.",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// Best-effort: most signers open this in a new tab. Try to close it;
|
||||
// the manual link below is the fallback when the browser refuses.
|
||||
window.setTimeout(() => {
|
||||
try {
|
||||
window.close();
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
}, 500);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
||||
<div className="text-center space-y-4 max-w-sm">
|
||||
<CheckCircle2 className="w-12 h-12 mx-auto text-green-500" />
|
||||
<h1 className="text-2xl font-semibold text-foreground">Signer connected</h1>
|
||||
<p className="text-muted-foreground">
|
||||
You can return to Shakespeare. Your login should complete automatically.
|
||||
</p>
|
||||
<a href="/" className="inline-block text-primary hover:text-primary/80 underline">
|
||||
Open Shakespeare
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RemoteLoginSuccess;
|
||||
Reference in new issue
Block a user