Skip to content

Commit cbbffda

Browse files
authored
Merge pull request #2121 from slntopp/dev-hot-fix
Dev hot fix
2 parents 9decbf2 + 851e1da commit cbbffda

File tree

1 file changed

+52
-49
lines changed

1 file changed

+52
-49
lines changed

admin-ui/src/views/login.vue

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
@keypress.enter="tryLogin"
3232
></v-text-field>
3333
<v-select
34-
v-if="typesAccounts.length > 1"
3534
v-model="type"
3635
class="type-select"
3736
:items="typesAccounts"
@@ -52,56 +51,60 @@
5251
</div>
5352
</template>
5453

55-
<script>
56-
import snackbar from "@/mixins/snackbar";
54+
<script setup>
55+
import { computed, ref } from "vue";
56+
import { useRouter } from "vue-router/composables";
57+
import { useStore } from "../store";
58+
59+
const loginFormRules = ref([(v) => !!v || "Required"]);
60+
const loginLoading = ref(false);
61+
const isLoginFailed = ref(false);
62+
const username = ref("");
63+
const password = ref("");
64+
const type = ref("Standard");
65+
const typesAccounts = ref(["Standard", "WHMCS"]);
66+
67+
const router = useRouter();
68+
const store = useStore();
69+
70+
const tryLogin = async () => {
71+
loginLoading.value = true;
72+
73+
try {
74+
const { token } = await store.dispatch("auth/login", {
75+
login: username.value,
76+
password: password.value,
77+
type: type.value.toLowerCase(),
78+
});
79+
store.commit("auth/setToken", "");
80+
81+
await store.dispatch("namespaces/fetchById", 0);
5782
83+
store.commit("auth/setToken", token);
84+
85+
await router.push({ name: "Home" });
86+
store.dispatch("auth/fetchUserData");
87+
} catch (error) {
88+
store.dispatch("auth/logout");
89+
store.commit("snackbar/showSnackbarError", {
90+
message: error.response.data.message || "Error during login",
91+
});
92+
if (error.response && error.response.status == 401) {
93+
isLoginFailed.value = true;
94+
}
95+
} finally {
96+
loginLoading.value = false;
97+
}
98+
};
99+
100+
const getErrorMessages = computed(() => {
101+
return isLoginFailed.value ? ["username or password is not correct"] : [];
102+
});
103+
</script>
104+
105+
<script>
58106
export default {
59-
name: "login-view",
60-
mixins: [snackbar],
61-
data() {
62-
return {
63-
loginFormRules: [(v) => !!v || "Required"],
64-
loginLoading: false,
65-
isLoginFailed: false,
66-
username: "",
67-
password: "",
68-
type: "Standard",
69-
typesAccounts: ["Standard"],
70-
};
71-
},
72-
methods: {
73-
tryLogin() {
74-
this.loginLoading = true;
75-
(this.isLoginFailed = false),
76-
this.$store
77-
.dispatch("auth/login", {
78-
login: this.username,
79-
password: this.password,
80-
type: this.type.toLowerCase(),
81-
})
82-
.then(() => {
83-
this.$router.push({ name: "Home" });
84-
this.$store.dispatch("auth/fetchUserData");
85-
})
86-
.catch((error) => {
87-
console.log(error);
88-
this.showSnackbarError({
89-
message: error.response.data.message || "Error during login",
90-
});
91-
if (error.response && error.response.status == 401) {
92-
this.isLoginFailed = true;
93-
}
94-
})
95-
.finally(() => {
96-
this.loginLoading = false;
97-
});
98-
},
99-
},
100-
computed: {
101-
getErrorMessages() {
102-
return this.isLoginFailed ? ["username or password is not correct"] : [];
103-
},
104-
},
107+
name: "LoginView",
105108
};
106109
</script>
107110

0 commit comments

Comments
 (0)