Added login functionality

This commit is contained in:
Keannu Christian Bernasol 2023-07-03 22:11:04 +08:00
parent 26b3db25f0
commit a634f07f2b
3 changed files with 43 additions and 9 deletions

View file

@ -40,11 +40,13 @@ export function UserLogin(user: LoginParams) {
.post("/api/v1/accounts/token/login/", user)
.then(async (response) => {
AsyncStorage.setItem("token", JSON.stringify(response.data.auth_token));
return true;
return [true];
})
.catch((error) => {
console.log("Login Failed: " + error);
return false;
console.log(
"Login Failed: " + error.response.status + " " + error.response.data
);
return [false, error.response.data];
});
}

View file

@ -2,8 +2,17 @@ export default function ParseError(text: string) {
return text
.replaceAll(/[{}()"]/g, " ")
.replaceAll(/,/g, "\n")
.replaceAll(":", "")
.replaceAll("[", "")
.replaceAll("]", "")
.replaceAll(".", "");
}
export function ParseLoginError(text: string) {
return text
.replaceAll(/[{}()"]/g, " ")
.replaceAll(/,/g, "\n")
.replaceAll("[", "")
.replaceAll("]", "")
.replaceAll(".", "")
.replaceAll("non_field_errors", "");
}