Refactor log-in API texts handling

This commit is contained in:
Florian Dupret 2021-04-29 09:53:42 +02:00
commit b61b799235
2 changed files with 9 additions and 17 deletions

View file

@ -30,11 +30,12 @@ function deleteErrorText(response) {
}
export const userAPI = {
async login(formData) {
let response = await apiReq.post(authURLs.token, formData, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
let response = await apiReq.post(
authURLs.token,
formData,
function() { return i18n.t('user.incorrect-username-or-password'); },
function() { return i18n.t('user.user-successfully-logged-in'); }
);
return response;
},
async refresh() {

View file

@ -61,7 +61,6 @@
<script>
import { api } from "@/api";
import utils from "@/utils";
export default {
props: {},
data() {
@ -92,20 +91,12 @@ export default {
let formData = new FormData();
formData.append("username", this.user.email);
formData.append("password", this.user.password);
let key;
try {
key = await api.users.login(formData);
} catch {
const response = await api.users.login(formData);
if (!response) {
this.error = true;
}
if (key.status != 200) {
utils.notify.error(this.$t('user.incorrect-username-or-password'));
this.error = true;
this.loading = false;
} else {
utils.notify.success(this.$t('user.user-successfully-logged-in'));
this.clear();
this.$store.commit("setToken", key.data.access_token);
this.$store.commit("setToken", response.data.access_token);
this.$emit("logged-in");
}