Replace KeyboardAvoidingView with KeyboardAwareScrollView, update dependencies, and handle login 401 error logging
This commit is contained in:
@@ -3,8 +3,8 @@ import api from '@/utils/api';
|
||||
import { AuthContext } from '@/utils/authContext';
|
||||
import { Eye, EyeOff, Lock, LogIn, Mail } from 'lucide-react-native';
|
||||
import React, { useContext, useState } from 'react';
|
||||
import { Image, Platform, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';
|
||||
import { Image, Platform, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';
|
||||
|
||||
export default function LoginScreen() {
|
||||
const alert = useAlert();
|
||||
@@ -40,19 +40,21 @@ export default function LoginScreen() {
|
||||
// Pass token and user data to the context which will handle saving and redirect
|
||||
authContext.logIn(token, user);
|
||||
} catch (error: any) {
|
||||
console.error("Login Error:", error);
|
||||
let message = "Si è verificato un errore durante l'accesso.";
|
||||
|
||||
if (error.response) {
|
||||
// Server error (e.g., 401 Invalid credentials)
|
||||
if (error.response.status === 401) {
|
||||
message = "Credenziali non valide."
|
||||
} else {
|
||||
console.error("Login Error:", error);
|
||||
message = `Errore Server: ${error.response.data.message || error.response.status}`;
|
||||
}
|
||||
} else if (error.request) {
|
||||
// Server not reachable
|
||||
console.error("Login Error:", error);
|
||||
message = "Impossibile contattare il server. Controlla la connessione.";
|
||||
} else {
|
||||
console.error("Login Error:", error);
|
||||
}
|
||||
|
||||
alert.showAlert('error', "Login Fallito", message);
|
||||
@@ -74,12 +76,13 @@ export default function LoginScreen() {
|
||||
|
||||
{/* Form Container */}
|
||||
<View className="flex-1 bg-white rounded-t-[2.5rem] px-8 pt-10 shadow-xl w-full">
|
||||
<KeyboardAvoidingView
|
||||
behavior={"padding"}
|
||||
keyboardVerticalOffset={100}
|
||||
className='flex-1 mh-600'
|
||||
<KeyboardAwareScrollView
|
||||
bottomOffset={Platform.OS === 'ios' ? 50 : 80}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
showsVerticalScrollIndicator={false}
|
||||
contentContainerStyle={{ paddingBottom: 40, flexGrow: 1 }}
|
||||
className="flex-1"
|
||||
>
|
||||
<ScrollView showsVerticalScrollIndicator={false} className="h-full">
|
||||
<View className="gap-6 flex flex-col" style={{ gap: '1.5rem' }}>
|
||||
{/* Input Username / Email */}
|
||||
<View>
|
||||
@@ -138,8 +141,7 @@ export default function LoginScreen() {
|
||||
{!isLoading && <LogIn size={24} color="white" pointerEvents="none" />}
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
</KeyboardAwareScrollView>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user