api login v3

This commit is contained in:
Sas Andy
2024-08-14 08:22:51 +07:00
parent f8ff853818
commit 83c805b4a7
6 changed files with 123 additions and 25 deletions

View File

@@ -1,6 +1,8 @@
// const URL = "/westone-api/v1/system/auth";
const URL = "https://devcpone.aplikasi.web.id/one-api/v1/system/auth/";
const URL = "https://devcpone.aplikasi.web.id/westone-api/v1/system/auth/";
const store = {
namespaced: true,
state() {
@@ -9,7 +11,15 @@ const store = {
data: null,
email: "",
password: "",
dialog_success: false
dialog_success: false,
loading: false,
errorMessage: "",
iin: window.i18n.global.t('message.login'),
alert: {
show: false,
type: 'info',
message: window.i18n.global.t('message.msgInfo')
}
};
},
mutations: {
@@ -30,6 +40,12 @@ const store = {
},
setDialogSuccess(state, data) {
state.dialog_success = data;
},
setLoading(state, data) {
state.loading = data;
},
setAlert(state, data) {
state.alert = data;
}
},
actions: {
@@ -39,7 +55,50 @@ const store = {
decrement({ commit }) {
commit('decrement');
},
async login({ state, commit }) {
commit('setLoading', true);
let alert = {
show: false,
type: 'info',
message: window.i18n.global.t('message.msgInfo')
}
let params = {
username: state.email,
password: state.password
};
console.log(params);
try {
const response = await axios.post(URL + '/login', params);
console.log(response.data)
if (response.data.status != 'OK') {
commit('setLoading', false);
if (response.data.message !== 'Invalid') {
alert.message = window.i18n.global.t('message.errorQuery');
} else {
alert.message = window.i18n.global.t('message.invalid');
}
alert.type = "error"
} else {
commit('setLoading', false);
commit('setData', response.data.data);
localStorage.setItem("token", response.data.data.token)
localStorage.setItem('user', JSON.stringify(response.data.data.user))
//console.log(localStorage.getItem("token"))
// if (data.user.is_courier === 'Y' && window.innerWidth < 600)
// window.location = "/one-ui/test/vuex/one-courier-mobile/";
// else
// window.location = "/" + response.data.data.user.M_UserGroupDashboard;
}
commit('setAlert', alert)
} catch (error) {
console.log(error)
commit('setLoading', false);
}
},
async loginState({ state, commit }) {
commit('setLoading', true);
const params = {
email: state.email,
password: state.pasword
@@ -47,8 +106,16 @@ const store = {
try {
const response = await axios.post(URL + '/login', params);
commit('setData', response.data);
if (response.status != 'OK') {
commit('setLoading', false);
} else {
commit('setLoading', false);
commit('setData', response.data);
}
} catch (error) {
commit('setLoading', false);
commit('setError', error);
}
},