а давай ща
Вот так чат ГоПоТы перевел ваш js в ts :
const login = (): void => {
setIsLoading(true);
if (user === "Patient") {
if (email.length < 5) {
Alert.alert("Email", "Invalid email");
setIsLoading(false);
} else {
axios
.post("/api/auth/login", {
email,
password,
})
.then((res) => {
AsyncStorage.setItem("user", user);
AsyncStorage.setItem("patientBody", JSON.stringify(res.data));
AsyncStorage.setItem("token", res.data.token);
setToken(res.data.token);
})
.catch((e) => {
console.log("login error " + e);
});
setIsLoading(false);
setFlag(true);
}
} else if (user === "Doctor") {
if (email.length < 5) {
Alert.alert("Email", "Invalid email");
setIsLoading(false);
} else {
axios
.post("/api/doctor/login", {
email,
password,
})
.then((res) => {
AsyncStorage.setItem("user", user);
AsyncStorage.setItem("doctorBody", JSON.stringify(res.data));
AsyncStorage.setItem("token", res.data.token);
setToken(res.data.token);
})
.catch((e) => {
console.log("login error " + e);
});
setIsLoading(false);
setFlag(true);
}
}
setIsLoading(false);
};
const logout = (): void => {
setIsLoading(true);
setToken(null);
AsyncStorage.removeItem("doctorBody");
AsyncStorage.removeItem("user");
AsyncStorage.removeItem("patientBody");
AsyncStorage.removeItem("token");
setIsLoading(false);
setFlag(false);
};
const isLoggedId = async (): Promise<void> => {
try {
let userType = await AsyncStorage.getItem("user");
if (userType) {
setUser(userType);
if (userType === "Patient") {
setIsLoading(true);
let patInfo = await AsyncStorage.getItem("patientBody");
let patTok = await AsyncStorage.getItem("token");
patInfo = JSON.parse(patInfo);
if (patInfo) {
setToken(patTok);
setPatientBody(patInfo);
}
setIsLoading(false);
setFlag(true);
} else if (userType === "Doctor") {
setIsLoading(true);
let docInfo = await AsyncStorage.getItem("doctorBody");
let docTok = await AsyncStorage.getItem("token");
docInfo = JSON.parse(docInfo);
if (docInfo) {
setToken(docTok);
set