mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
feat: add client-initiated NIP-46 (nostrconnect://) login support
Upgrade to @nostrify/[email protected] and implement the nostrconnect:// login flow: - QR code display on desktop, deep link on mobile - Copy URI button, retry on timeout, abort on dialog close - Bunker URI manual input as fallback under the Remote Signer tab - Add QRCodeCanvas component using the existing qrcode dependency
This commit is contained in:
5 files changed
+284
-63
No files matched your search
Generated
+8
-8
@@ -12,7 +12,7 @@
|
|||||||
"@getalby/sdk": "^5.1.1",
|
"@getalby/sdk": "^5.1.1",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
"@nostrify/nostrify": "^0.50.2",
|
"@nostrify/nostrify": "^0.50.2",
|
||||||
"@nostrify/react": "^0.2.27",
|
"@nostrify/react": "^0.3.0",
|
||||||
"@radix-ui/react-accordion": "^1.2.0",
|
"@radix-ui/react-accordion": "^1.2.0",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.1",
|
"@radix-ui/react-alert-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
||||||
@@ -881,9 +881,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@nostrify/nostrify": {
|
"node_modules/@nostrify/nostrify": {
|
||||||
"version": "0.50.2",
|
"version": "0.50.5",
|
||||||
"resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.50.2.tgz",
|
"resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.50.5.tgz",
|
||||||
"integrity": "sha512-7kw718SdtDM49PbD/U9KmvjSrPWAHS9mNzA4LnY5z/gEPPAy54aAAY/4sUnS9I0CJdUbYPFcf00muhtQgRp2ew==",
|
"integrity": "sha512-0XlNz/aVKl3ODxAZYRbNsa9IzwLsQd0ACxq4EvPBCGZLvpSr3GW14GK13lX0FLx1UAy94xuvsbYGqkiVigBYnQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nostrify/types": "0.36.9",
|
"@nostrify/types": "0.36.9",
|
||||||
"@scure/base": "^2.0.0",
|
"@scure/base": "^2.0.0",
|
||||||
@@ -922,11 +922,11 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@nostrify/react": {
|
"node_modules/@nostrify/react": {
|
||||||
"version": "0.2.27",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.2.27.tgz",
|
"resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.3.0.tgz",
|
||||||
"integrity": "sha512-WZ7JniKDuRI3W6zFcjgHSoENw9prPZWWMDQX9XWji1TEHb8i9liGmXpdePkwWsBG6dnK4QUDtMub+i8SyIJwRg==",
|
"integrity": "sha512-Omoxiz3/u0Ab7uLo1Icx9FL8XDx8wiBpaPgdfHarxndwVg7LuAvTNLBVfKUj5n6iFFCZx3yorgg1jSBwi3k3NA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nostrify/nostrify": "0.50.2",
|
"@nostrify/nostrify": "0.50.5",
|
||||||
"@nostrify/types": "0.36.9",
|
"@nostrify/types": "0.36.9",
|
||||||
"@tanstack/react-query": "^5.69.0",
|
"@tanstack/react-query": "^5.69.0",
|
||||||
"nostr-tools": "^2.13.0",
|
"nostr-tools": "^2.13.0",
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
"@getalby/sdk": "^5.1.1",
|
"@getalby/sdk": "^5.1.1",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
"@nostrify/nostrify": "^0.50.2",
|
"@nostrify/nostrify": "^0.50.2",
|
||||||
"@nostrify/react": "^0.2.27",
|
"@nostrify/react": "^0.3.0",
|
||||||
"@radix-ui/react-accordion": "^1.2.0",
|
"@radix-ui/react-accordion": "^1.2.0",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.1",
|
"@radix-ui/react-alert-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
// NOTE: This file is stable and usually should not be modified.
|
// NOTE: This file is stable and usually should not be modified.
|
||||||
// It is important that all functionality in this file is preserved, and should only be modified if explicitly requested.
|
// It is important that all functionality in this file is preserved, and should only be modified if explicitly requested.
|
||||||
|
|
||||||
import React, { useRef, useState, useEffect } from 'react';
|
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
||||||
import { Upload, AlertTriangle, ChevronDown } from 'lucide-react';
|
import { Upload, AlertTriangle, ChevronDown, ChevronUp, Loader2, Copy, Check, ExternalLink } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Dialog, DialogContent, DialogHeader } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogHeader } from "@/components/ui/dialog";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
import { Collapsible, CollapsibleContent } from '@/components/ui/collapsible';
|
||||||
import { useLoginActions } from '@/hooks/useLoginActions';
|
import { QRCodeCanvas } from '@/components/ui/qrcode';
|
||||||
|
import {
|
||||||
|
useLoginActions,
|
||||||
|
generateNostrConnectParams,
|
||||||
|
generateNostrConnectURI,
|
||||||
|
type NostrConnectParams,
|
||||||
|
} from '@/hooks/useLoginActions';
|
||||||
import { DialogTitle } from '@radix-ui/react-dialog';
|
import { DialogTitle } from '@radix-ui/react-dialog';
|
||||||
|
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||||
|
|
||||||
interface LoginDialogProps {
|
interface LoginDialogProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -26,11 +33,23 @@ const validateBunkerUri = (uri: string) => {
|
|||||||
return uri.startsWith('bunker://');
|
return uri.startsWith('bunker://');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Check if running on actual mobile device (not just small screen) */
|
||||||
|
function isMobileDevice(): boolean {
|
||||||
|
if (typeof navigator === 'undefined') return false;
|
||||||
|
return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) => {
|
const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isFileLoading, setIsFileLoading] = useState(false);
|
const [isFileLoading, setIsFileLoading] = useState(false);
|
||||||
const [nsec, setNsec] = useState('');
|
const [nsec, setNsec] = useState('');
|
||||||
const [bunkerUri, setBunkerUri] = useState('');
|
const [bunkerUri, setBunkerUri] = useState('');
|
||||||
|
const [nostrConnectParams, setNostrConnectParams] = useState<NostrConnectParams | null>(null);
|
||||||
|
const [nostrConnectUri, setNostrConnectUri] = useState<string>('');
|
||||||
|
const [isWaitingForConnect, setIsWaitingForConnect] = useState(false);
|
||||||
|
const [connectError, setConnectError] = useState<string | null>(null);
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const [showBunkerInput, setShowBunkerInput] = useState(false);
|
||||||
const [errors, setErrors] = useState<{
|
const [errors, setErrors] = useState<{
|
||||||
nsec?: string;
|
nsec?: string;
|
||||||
bunker?: string;
|
bunker?: string;
|
||||||
@@ -38,24 +57,95 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
extension?: string;
|
extension?: string;
|
||||||
}>({});
|
}>({});
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const abortControllerRef = useRef<AbortController | null>(null);
|
||||||
const login = useLoginActions();
|
const login = useLoginActions();
|
||||||
|
|
||||||
// Reset all state when dialog opens/closes
|
// Check if on mobile device
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
// Check if extension is available
|
||||||
|
const hasExtension = 'nostr' in window;
|
||||||
|
|
||||||
|
// Generate nostrconnect params (sync) - just creates the QR code data
|
||||||
|
const generateConnectSession = useCallback(() => {
|
||||||
|
const relayUrls = login.getRelayUrls();
|
||||||
|
const params = generateNostrConnectParams(relayUrls);
|
||||||
|
const uri = generateNostrConnectURI(params, {
|
||||||
|
callback: isMobileDevice() ? `${window.location.origin}/remoteloginsuccess` : undefined,
|
||||||
|
});
|
||||||
|
setNostrConnectParams(params);
|
||||||
|
setNostrConnectUri(uri);
|
||||||
|
setConnectError(null);
|
||||||
|
}, [login]);
|
||||||
|
|
||||||
|
// Start listening for connection (async) - runs after params are set
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (!nostrConnectParams || isWaitingForConnect) return;
|
||||||
// Reset state when dialog opens
|
|
||||||
setIsLoading(false);
|
const startListening = async () => {
|
||||||
setIsFileLoading(false);
|
setIsWaitingForConnect(true);
|
||||||
|
abortControllerRef.current = new AbortController();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await login.nostrconnect(nostrConnectParams, abortControllerRef.current.signal);
|
||||||
|
onLogin();
|
||||||
|
onClose();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Nostrconnect failed:', error);
|
||||||
|
// Don't show error if it was aborted (dialog closed)
|
||||||
|
if (error instanceof Error && error.name !== 'AbortError') {
|
||||||
|
setConnectError(error.message);
|
||||||
|
}
|
||||||
|
setIsWaitingForConnect(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
startListening();
|
||||||
|
}, [nostrConnectParams, login, onLogin, onClose, isWaitingForConnect]);
|
||||||
|
|
||||||
|
// Clean up on close
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen) {
|
||||||
|
setNostrConnectParams(null);
|
||||||
|
setNostrConnectUri('');
|
||||||
|
setIsWaitingForConnect(false);
|
||||||
|
setConnectError(null);
|
||||||
setNsec('');
|
setNsec('');
|
||||||
setBunkerUri('');
|
setBunkerUri('');
|
||||||
setErrors({});
|
setErrors({});
|
||||||
// Reset file input
|
setIsLoading(false);
|
||||||
|
setIsFileLoading(false);
|
||||||
|
setShowBunkerInput(false);
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
}
|
||||||
if (fileInputRef.current) {
|
if (fileInputRef.current) {
|
||||||
fileInputRef.current.value = '';
|
fileInputRef.current.value = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
|
// Retry connection with new params
|
||||||
|
const handleRetry = useCallback(() => {
|
||||||
|
setNostrConnectParams(null);
|
||||||
|
setNostrConnectUri('');
|
||||||
|
setIsWaitingForConnect(false);
|
||||||
|
setConnectError(null);
|
||||||
|
// Generate new session after state clears
|
||||||
|
setTimeout(() => generateConnectSession(), 0);
|
||||||
|
}, [generateConnectSession]);
|
||||||
|
|
||||||
|
const handleCopyUri = async () => {
|
||||||
|
await navigator.clipboard.writeText(nostrConnectUri);
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Open the nostrconnect URI in the system - this will launch a signer app like Amber if installed
|
||||||
|
const handleOpenSignerApp = () => {
|
||||||
|
if (!nostrConnectUri) return;
|
||||||
|
window.location.href = nostrConnectUri;
|
||||||
|
};
|
||||||
|
|
||||||
const handleExtensionLogin = async () => {
|
const handleExtensionLogin = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setErrors(prev => ({ ...prev, extension: undefined }));
|
setErrors(prev => ({ ...prev, extension: undefined }));
|
||||||
@@ -69,8 +159,6 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
onClose();
|
onClose();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
console.error('Bunker login failed:', error);
|
|
||||||
console.error('Nsec login failed:', error);
|
|
||||||
console.error('Extension login failed:', error);
|
console.error('Extension login failed:', error);
|
||||||
setErrors(prev => ({
|
setErrors(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
@@ -170,16 +258,23 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasExtension = 'nostr' in window;
|
|
||||||
const [isMoreOptionsOpen, setIsMoreOptionsOpen] = useState(false);
|
const [isMoreOptionsOpen, setIsMoreOptionsOpen] = useState(false);
|
||||||
|
|
||||||
const renderTabs = () => (
|
const renderTabs = () => (
|
||||||
<Tabs defaultValue="key" className="w-full">
|
<Tabs
|
||||||
|
defaultValue="key"
|
||||||
|
className="w-full"
|
||||||
|
onValueChange={(value) => {
|
||||||
|
if (value === 'remote' && !nostrConnectParams && !connectError) {
|
||||||
|
generateConnectSession();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<TabsList className="grid w-full grid-cols-2 bg-muted/80 rounded-lg mb-4">
|
<TabsList className="grid w-full grid-cols-2 bg-muted/80 rounded-lg mb-4">
|
||||||
<TabsTrigger value="key" className="flex items-center gap-2">
|
<TabsTrigger value="key" className="flex items-center gap-2">
|
||||||
<span>Secret Key</span>
|
<span>Secret Key</span>
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
<TabsTrigger value="bunker" className="flex items-center gap-2">
|
<TabsTrigger value="remote" className="flex items-center gap-2">
|
||||||
<span>Remote Signer</span>
|
<span>Remote Signer</span>
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
@@ -244,39 +339,113 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
</form>
|
</form>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
<TabsContent value='bunker' className='space-y-4'>
|
<TabsContent value='remote' className='space-y-4'>
|
||||||
<form onSubmit={(e) => {
|
{/* Nostrconnect Section */}
|
||||||
e.preventDefault();
|
<div className='flex flex-col items-center space-y-4'>
|
||||||
handleBunkerLogin();
|
{connectError ? (
|
||||||
}} className='space-y-4'>
|
<div className='flex flex-col items-center space-y-4 py-4'>
|
||||||
<div className='space-y-2'>
|
<p className='text-sm text-red-500 text-center'>{connectError}</p>
|
||||||
<Input
|
<Button variant='outline' onClick={handleRetry}>
|
||||||
id='bunkerUri'
|
Retry
|
||||||
value={bunkerUri}
|
</Button>
|
||||||
onChange={(e) => {
|
</div>
|
||||||
setBunkerUri(e.target.value);
|
) : nostrConnectUri ? (
|
||||||
if (errors.bunker) setErrors(prev => ({ ...prev, bunker: undefined }));
|
<>
|
||||||
}}
|
{/* QR Code - only show on desktop */}
|
||||||
className={`rounded-lg border-gray-300 dark:border-gray-700 focus-visible:ring-primary ${
|
{!isMobile && (
|
||||||
errors.bunker ? 'border-red-500' : ''
|
<div className='p-4 bg-white dark:bg-white rounded-xl'>
|
||||||
}`}
|
<QRCodeCanvas
|
||||||
placeholder='bunker://'
|
value={nostrConnectUri}
|
||||||
autoComplete="off"
|
size={180}
|
||||||
/>
|
level='M'
|
||||||
{errors.bunker && (
|
/>
|
||||||
<p className="text-sm text-red-500">{errors.bunker}</p>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button
|
{/* Status message */}
|
||||||
type="submit"
|
<div className='flex items-center gap-2 text-sm text-muted-foreground'>
|
||||||
size="lg"
|
<span>{isMobile ? 'Tap to open your signer app' : 'Scan with your signer app'}</span>
|
||||||
className='w-full'
|
</div>
|
||||||
disabled={isLoading || !bunkerUri.trim()}
|
|
||||||
|
{/* Open Signer App button - primary action on mobile */}
|
||||||
|
{isMobile && (
|
||||||
|
<Button
|
||||||
|
className='w-full gap-2 py-6 rounded-full'
|
||||||
|
onClick={handleOpenSignerApp}
|
||||||
|
>
|
||||||
|
<ExternalLink className='w-5 h-5' />
|
||||||
|
Open Signer App
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Copy button */}
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
size={isMobile ? 'default' : 'sm'}
|
||||||
|
className={isMobile ? 'w-full gap-2 rounded-full' : 'gap-2'}
|
||||||
|
onClick={handleCopyUri}
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<>
|
||||||
|
<Check className='w-4 h-4' />
|
||||||
|
Copied!
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Copy className='w-4 h-4' />
|
||||||
|
Copy URI
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className='flex items-center justify-center h-[100px]'>
|
||||||
|
<Loader2 className='w-8 h-8 animate-spin text-muted-foreground' />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Manual URI input section - collapsible */}
|
||||||
|
<div className='pt-4 border-t border-gray-200 dark:border-gray-700'>
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
onClick={() => setShowBunkerInput(!showBunkerInput)}
|
||||||
|
className='flex items-center justify-center gap-2 w-full text-sm text-muted-foreground hover:text-foreground transition-colors py-2'
|
||||||
>
|
>
|
||||||
{isLoading ? 'Connecting...' : 'Log in'}
|
<span>Enter bunker URI manually</span>
|
||||||
</Button>
|
{showBunkerInput ? (
|
||||||
</form>
|
<ChevronUp className='w-4 h-4' />
|
||||||
|
) : (
|
||||||
|
<ChevronDown className='w-4 h-4' />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{showBunkerInput && (
|
||||||
|
<div className='space-y-3 mt-3'>
|
||||||
|
<div className='space-y-2'>
|
||||||
|
<Input
|
||||||
|
id='connectBunkerUri'
|
||||||
|
value={bunkerUri}
|
||||||
|
onChange={(e) => setBunkerUri(e.target.value)}
|
||||||
|
className='rounded-lg border-gray-300 dark:border-gray-700 focus-visible:ring-primary text-base md:text-sm'
|
||||||
|
placeholder='bunker://'
|
||||||
|
/>
|
||||||
|
{bunkerUri && !validateBunkerUri(bunkerUri) && (
|
||||||
|
<p className='text-red-500 text-xs'>Invalid bunker URI format</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className='w-full rounded-full py-4'
|
||||||
|
variant='outline'
|
||||||
|
onClick={handleBunkerLogin}
|
||||||
|
disabled={isLoading || !bunkerUri.trim() || !validateBunkerUri(bunkerUri)}
|
||||||
|
>
|
||||||
|
{isLoading ? 'Connecting...' : 'Connect'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
@@ -297,7 +466,7 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
<div className='px-6 pb-6 space-y-4 overflow-y-auto'>
|
<div className='px-6 pb-6 space-y-4 overflow-y-auto'>
|
||||||
{/* Extension Login Button - shown if extension is available */}
|
{/* Extension Login Button - shown if extension is available */}
|
||||||
{hasExtension && (
|
{hasExtension && (
|
||||||
<div className="space-y-4">
|
<div className="space-y-3">
|
||||||
{errors.extension && (
|
{errors.extension && (
|
||||||
<Alert variant="destructive">
|
<Alert variant="destructive">
|
||||||
<AlertTriangle className="h-4 w-4" />
|
<AlertTriangle className="h-4 w-4" />
|
||||||
@@ -317,12 +486,14 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin }) =
|
|||||||
{/* Tabs - wrapped in collapsible if extension is available, otherwise shown directly */}
|
{/* Tabs - wrapped in collapsible if extension is available, otherwise shown directly */}
|
||||||
{hasExtension ? (
|
{hasExtension ? (
|
||||||
<Collapsible className="space-y-4" open={isMoreOptionsOpen} onOpenChange={setIsMoreOptionsOpen}>
|
<Collapsible className="space-y-4" open={isMoreOptionsOpen} onOpenChange={setIsMoreOptionsOpen}>
|
||||||
<CollapsibleTrigger asChild>
|
<button
|
||||||
<button className="w-full flex items-center justify-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors">
|
type="button"
|
||||||
<span>More Options</span>
|
onClick={() => setIsMoreOptionsOpen(!isMoreOptionsOpen)}
|
||||||
<ChevronDown className={`w-4 h-4 transition-transform ${isMoreOptionsOpen ? 'rotate-180' : ''}`} />
|
className="w-full flex items-center justify-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors py-2"
|
||||||
</button>
|
>
|
||||||
</CollapsibleTrigger>
|
<span>More Options</span>
|
||||||
|
<ChevronDown className={`w-4 h-4 transition-transform ${isMoreOptionsOpen ? 'rotate-180' : ''}`} />
|
||||||
|
</button>
|
||||||
|
|
||||||
<CollapsibleContent>
|
<CollapsibleContent>
|
||||||
{renderTabs()}
|
{renderTabs()}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import QRCode from 'qrcode';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
|
interface QRCodeCanvasProps {
|
||||||
|
value: string;
|
||||||
|
size?: number;
|
||||||
|
level?: 'L' | 'M' | 'Q' | 'H';
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function QRCodeCanvas({ value, size = 256, level = 'M', className }: QRCodeCanvasProps) {
|
||||||
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!canvasRef.current) return;
|
||||||
|
|
||||||
|
QRCode.toCanvas(
|
||||||
|
canvasRef.current,
|
||||||
|
value,
|
||||||
|
{
|
||||||
|
width: size,
|
||||||
|
margin: 1,
|
||||||
|
errorCorrectionLevel: level,
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
if (error) console.error('QR Code generation error:', error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, [value, size, level]);
|
||||||
|
|
||||||
|
return <canvas ref={canvasRef} className={className} />;
|
||||||
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import { useNostr } from '@nostrify/react';
|
import { useNostr } from '@nostrify/react';
|
||||||
import { NLogin, useNostrLogin } from '@nostrify/react/login';
|
import { NLogin, type NostrConnectParams, useNostrLogin } from '@nostrify/react/login';
|
||||||
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
|
|
||||||
// NOTE: This file should not be edited except for adding new login methods.
|
// NOTE: This file should not be edited except for adding new login methods.
|
||||||
|
|
||||||
|
export type { NostrConnectParams };
|
||||||
|
export { generateNostrConnectParams, generateNostrConnectURI } from '@nostrify/react/login';
|
||||||
|
|
||||||
export function useLoginActions() {
|
export function useLoginActions() {
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
const { logins, addLogin, removeLogin } = useNostrLogin();
|
const { logins, addLogin, removeLogin } = useNostrLogin();
|
||||||
|
const { config } = useAppContext();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Login with a Nostr secret key
|
// Login with a Nostr secret key
|
||||||
@@ -23,6 +28,19 @@ export function useLoginActions() {
|
|||||||
const login = await NLogin.fromExtension();
|
const login = await NLogin.fromExtension();
|
||||||
addLogin(login);
|
addLogin(login);
|
||||||
},
|
},
|
||||||
|
// Login via nostrconnect:// (client-initiated NIP-46)
|
||||||
|
// The client displays a QR code and waits for the remote signer to connect
|
||||||
|
async nostrconnect(params: NostrConnectParams, signal?: AbortSignal): Promise<void> {
|
||||||
|
const login = await NLogin.fromNostrConnect(params, nostr, { signal });
|
||||||
|
addLogin(login);
|
||||||
|
},
|
||||||
|
// Get the relay URLs for NIP-46 nostrconnect communication
|
||||||
|
getRelayUrls(): string[] {
|
||||||
|
const relays = config.relayMetadata.relays
|
||||||
|
.filter((r) => r.write)
|
||||||
|
.map((r) => r.url);
|
||||||
|
return relays.length > 0 ? relays : ['wss://relay.damus.io'];
|
||||||
|
},
|
||||||
// Log out the current user
|
// Log out the current user
|
||||||
async logout(): Promise<void> {
|
async logout(): Promise<void> {
|
||||||
const login = logins[0];
|
const login = logins[0];
|
||||||
|
|||||||
Reference in new issue
Block a user