Added login error messages
This commit is contained in:
parent
b2a48861e7
commit
fd46581543
@ -15,6 +15,7 @@ import {
|
|||||||
DEFAUL_PVE_USER,
|
DEFAUL_PVE_USER,
|
||||||
DEFAUL_PVE_PASSWORD,
|
DEFAUL_PVE_PASSWORD,
|
||||||
} from "react-native-dotenv";
|
} from "react-native-dotenv";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
interface FormFieldProps extends TextInputProps {
|
interface FormFieldProps extends TextInputProps {
|
||||||
label: string;
|
label: string;
|
||||||
@ -49,13 +50,26 @@ export default function Login() {
|
|||||||
const [domain, setDomain] = useState(DEFAUL_PVE_URL ?? "");
|
const [domain, setDomain] = useState(DEFAUL_PVE_URL ?? "");
|
||||||
const [username, setUsername] = useState(DEFAUL_PVE_USER ?? "");
|
const [username, setUsername] = useState(DEFAUL_PVE_USER ?? "");
|
||||||
const [password, setPassword] = useState(DEFAUL_PVE_PASSWORD ?? "");
|
const [password, setPassword] = useState(DEFAUL_PVE_PASSWORD ?? "");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const ticketMut = useTicketMut({
|
const ticketMut = useTicketMut({
|
||||||
onSuccess: ({ data: ticketData }) => {
|
onSuccess: ({ data: ticketData }) => {
|
||||||
console.log({ ticketData });
|
|
||||||
authStore.update({ domain, username, 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 (
|
return (
|
||||||
@ -105,6 +119,7 @@ export default function Login() {
|
|||||||
>
|
>
|
||||||
<Text style={tw.style("text-white font-semibold py-3")}>Sign In</Text>
|
<Text style={tw.style("text-white font-semibold py-3")}>Sign In</Text>
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
|
<Text style={tw.style("text-center mt-2 font-semibold")}>{error}</Text>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user