import React from 'react'; import { View, StyleSheet, ScrollView, Button, Text, Platform } from 'react-native'; import { useAuthState, useAuth } from '@/lib/auth/AuthProvider'; import AuthStatus from '@/components/auth/AuthStatus'; import { StatusBar } from 'expo-status-bar'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Stack } from 'expo-router'; /** * Test page for the new authentication system */ export default function AuthTestPage() { const { top, bottom } = useSafeAreaInsets(); const authState = useAuthState(); const { authService } = useAuth(); const [privateKey, setPrivateKey] = React.useState(''); // Login with private key const handleLoginWithPrivateKey = async () => { try { // For testing, just use a generated key or a newly generated one if (privateKey) { await authService.loginWithPrivateKey(privateKey); } else { await authService.createEphemeralKey(); } } catch (error) { console.error("Login error:", error); } }; // Create ephemeral key const handleCreateEphemeralKey = async () => { try { await authService.createEphemeralKey(); } catch (error) { console.error("Ephemeral key error:", error); } }; // Generate signing operations for testing const handleSimulateSigningOperations = async () => { // We can only test this if we're authenticated if (authState.status !== 'authenticated') { console.log("Can't simulate signing operations when not authenticated"); return; } // Simulate signing 3 operations with delays for (let i = 0; i < 3; i++) { // Create a minimal NostrEvent for testing const event = { id: `event-${i}`, pubkey: authState.user.pubkey, content: `Test event ${i}`, kind: 1, created_at: Math.floor(Date.now() / 1000), tags: [], sig: '', }; // Create a proper SigningOperation const operation = { event: event as any, // Type assertion to satisfy NostrEvent requirement timestamp: Date.now(), resolve: () => {}, reject: () => {}, }; // Start signing authState.setSigningInProgress(true, operation); // After 1 second, complete the operation setTimeout(() => { authState.setSigningInProgress(false, operation); }, 1000 * (i + 1)); } }; return ( Authentication System Test {/* Current authentication status */} Current Status {/* Authentication actions */} Authentication Actions