From fd46581543f3c172e55fbb072d43b2f2ae1cb1d5 Mon Sep 17 00:00:00 2001 From: niku Date: Sat, 10 Jun 2023 20:33:56 +0200 Subject: [PATCH] Added login error messages --- components/login/index.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/login/index.tsx b/components/login/index.tsx index 60f3439..17c0fc0 100644 --- a/components/login/index.tsx +++ b/components/login/index.tsx @@ -15,6 +15,7 @@ import { DEFAUL_PVE_USER, DEFAUL_PVE_PASSWORD, } from "react-native-dotenv"; +import { AxiosError } from "axios"; interface FormFieldProps extends TextInputProps { label: string; @@ -49,13 +50,26 @@ export default function Login() { const [domain, setDomain] = useState(DEFAUL_PVE_URL ?? ""); const [username, setUsername] = useState(DEFAUL_PVE_USER ?? ""); const [password, setPassword] = useState(DEFAUL_PVE_PASSWORD ?? ""); + const [error, setError] = useState(""); const authStore = useAuthStore(); const ticketMut = useTicketMut({ onSuccess: ({ data: ticketData }) => { - console.log({ ticketData }); authStore.update({ domain, username, ticketData }); }, + onError: (error: AxiosError) => { + console.log(error); + switch (error.code) { + case "ERR_BAD_REQUEST": + setError("Invalid username or password"); + return; + case "ERR_NETWORK": + setError("Failed to connect to server"); + return; + default: + setError("Something unexpected happened"); + } + }, }); return ( @@ -105,6 +119,7 @@ export default function Login() { > Sign In + {error} );