fix: callback enhancements

This commit is contained in:
Derek Ross committed 2025-12-30 21:13:23 -05:00
1 parent ac88a3a5c1
commit 8a4f97beba
1 file changed
+12 -5
+12 -5
View File
@@ -3,8 +3,8 @@ import { useNavigate } from 'react-router-dom';
import { useNostrLogin } from '@nostrify/react/login'; import { useNostrLogin } from '@nostrify/react/login';
import { Loader2, CheckCircle, XCircle } from 'lucide-react'; import { Loader2, CheckCircle, XCircle } from 'lucide-react';
// Storage key used by @nostrify/react for logins // Storage key must match the one in App.tsx NostrLoginProvider
const LOGINS_STORAGE_KEY = 'nostrify:logins'; const LOGINS_STORAGE_KEY = 'nostr:login';
export function RemoteLoginSuccess() { export function RemoteLoginSuccess() {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -33,7 +33,11 @@ export function RemoteLoginSuccess() {
if (isLoggedIn) { if (isLoggedIn) {
setStatus('success'); setStatus('success');
const timer = setTimeout(() => { const timer = setTimeout(() => {
navigate('/', { replace: true }); // Try to close this tab (works if opened by signer app)
// This leaves the user on the original tab which should detect the login
window.close();
// If we're still here (close didn't work), do a full page redirect
window.location.href = '/';
}, 1500); }, 1500);
return () => clearTimeout(timer); return () => clearTimeout(timer);
} }
@@ -57,7 +61,10 @@ export function RemoteLoginSuccess() {
const parsed = JSON.parse(e.newValue); const parsed = JSON.parse(e.newValue);
if (Array.isArray(parsed) && parsed.length > 0) { if (Array.isArray(parsed) && parsed.length > 0) {
setStatus('success'); setStatus('success');
setTimeout(() => navigate('/', { replace: true }), 1500); setTimeout(() => {
window.close();
window.location.href = '/';
}, 1500);
} }
} catch { } catch {
// Ignore parse errors // Ignore parse errors
@@ -67,7 +74,7 @@ export function RemoteLoginSuccess() {
window.addEventListener('storage', handleStorage); window.addEventListener('storage', handleStorage);
return () => window.removeEventListener('storage', handleStorage); return () => window.removeEventListener('storage', handleStorage);
}, [navigate]); }, []);
return ( return (
<div className="min-h-screen flex items-center justify-center bg-background"> <div className="min-h-screen flex items-center justify-center bg-background">