mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
Refactor log-in API texts handling
This commit is contained in:
parent
41b3b88826
commit
b61b799235
2 changed files with 9 additions and 17 deletions
|
@ -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() {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue