-
Bart Chou authored
now server can create login cookie and client can store cookie in broser. We use userId as token for login cookie for convinence for now.
Bart Chou authorednow server can create login cookie and client can store cookie in broser. We use userId as token for login cookie for convinence for now.
auth.ts 886 B
import * as UserService from "../../services/UserService";
const state = () => ({
loginStatus: false,
});
const getters = {
getLoginStatus(state: any) {
return state.loginStatus;
},
};
const actions = {
async loginApi({ commit }: any, payload: any) {
const response = await UserService.loginUser(JSON.stringify(payload))
.catch((error) => alert(error));
if (response.status == "OK") {
commit("setLoginStatus", true);
} else {
alert(response.message)
}
},
logOutApi({ commit }: any) {
// todo: clear session in backend
console.log("logOut")
commit("setLoginStatus", false);
}
};
const mutations = {
setLoginStatus(state: any, data: any) {
state.loginStatus = data;
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};