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}
);