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 = { export const userAPI = {
async login(formData) { async login(formData) {
let response = await apiReq.post(authURLs.token, formData, { let response = await apiReq.post(
headers: { authURLs.token,
"Content-Type": "application/x-www-form-urlencoded", formData,
}, function() { return i18n.t('user.incorrect-username-or-password'); },
}); function() { return i18n.t('user.user-successfully-logged-in'); }
);
return response; return response;
}, },
async refresh() { async refresh() {

View file

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