import React from 'react'; import { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator } from 'react-native'; import { useAuthState, useAuth } from '@/lib/auth/AuthProvider'; /** * Component that displays the current authentication status and provides logout functionality */ export default function AuthStatus() { const authState = useAuthState(); const { authService } = useAuth(); /** * Handle logout button press */ const handleLogout = async () => { try { await authService.logout(); } catch (error) { console.error("Logout error:", error); } }; // Render different UI based on auth state switch (authState.status) { case 'unauthenticated': return ( Not logged in ); case 'authenticating': return ( Logging in... ({authState.method}) ); case 'authenticated': return ( Logged in as: {authState.user?.npub?.substring(0, 8)}... Method: {authState.method} Logout ); case 'signing': return ( Logged in as: {authState.user?.npub?.substring(0, 8)}... Signing {authState.operationCount} operations... Logout ); case 'error': return ( Error: {authState.error?.message || "Unknown error"} Reset ); default: return null; } } const styles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 10, borderRadius: 8, backgroundColor: '#f5f5f5', marginVertical: 8, }, userInfo: { flex: 1, }, text: { fontSize: 14, color: '#333', }, methodText: { fontSize: 12, color: '#666', marginTop: 2, }, spinner: { marginRight: 10, }, signingContainer: { flexDirection: 'row', alignItems: 'center', marginTop: 4, }, signingText: { fontSize: 12, color: '#0066cc', }, errorText: { fontSize: 14, color: '#d32f2f', flex: 1, }, logoutButton: { backgroundColor: '#d32f2f', paddingHorizontal: 16, paddingVertical: 8, borderRadius: 4, marginLeft: 16, }, logoutText: { color: '#ffffff', fontSize: 12, fontWeight: 'bold', }, });