mirror of
https://github.com/dborth/vbagx.git
synced 2024-12-28 03:31:49 +01:00
Updates:
-Add location data to user login -Fix delete item on localforage on user state
This commit is contained in:
parent
ca122b6d23
commit
7cec420ced
@ -7,26 +7,30 @@ const user = createStore({
|
||||
token: '',
|
||||
user: {},
|
||||
roles: [],
|
||||
location: {},
|
||||
},
|
||||
actions: {
|
||||
async setBasicData({ dispatch }, { token, user, roles }){
|
||||
async setBasicData({ dispatch }, { token, user, roles, location }){
|
||||
await localForage.setItem('user', user);
|
||||
await localForage.setItem('token', token);
|
||||
await localForage.setItem('roles', roles);
|
||||
dispatch('auth_success', { token, user, roles });
|
||||
await localForage.setItem('location', location);
|
||||
dispatch('auth_success', { token, user, roles, location });
|
||||
},
|
||||
async getBasicData({ dispatch }){
|
||||
const result = {
|
||||
user: await localForage.getItem('user'),
|
||||
token: await localForage.getItem('token'),
|
||||
roles: await localForage.getItem('roles'),
|
||||
location: await localForage.getItem('location'),
|
||||
}
|
||||
dispatch('auth_success', result);
|
||||
},
|
||||
async clearBasicData(){
|
||||
await localForage.removeItem('user');
|
||||
await localForage.removeItem('token');
|
||||
await localForage.removeItem('roles');
|
||||
await localForage.deleteItem('user');
|
||||
await localForage.deleteItem('token');
|
||||
await localForage.deleteItem('roles');
|
||||
await localForage.deleteItem('location');
|
||||
},
|
||||
async checkData({ dispatch }){
|
||||
let token = await localForage.getItem('token');
|
||||
@ -44,9 +48,11 @@ const user = createStore({
|
||||
|
||||
delete response.data.token;
|
||||
delete response.data.roles;
|
||||
delete response.data.location;
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
dispatch('auth_error');
|
||||
await clearBasicData();
|
||||
throw new error;
|
||||
@ -63,15 +69,17 @@ const user = createStore({
|
||||
state.token = '';
|
||||
state.user = {};
|
||||
state.roles = [];
|
||||
state.location = {};
|
||||
},
|
||||
auth_request({ state }){
|
||||
state.status = 'loading';
|
||||
},
|
||||
auth_success({ state }, { token, user, roles }){
|
||||
auth_success({ state }, { token, user, roles, location }){
|
||||
state.status = 'success';
|
||||
state.token = token;
|
||||
state.user = user;
|
||||
state.roles = roles;
|
||||
state.location = location;
|
||||
},
|
||||
auth_error({ state }){
|
||||
state.status = 'error'
|
||||
@ -91,6 +99,9 @@ const user = createStore({
|
||||
roles({ state }){
|
||||
return state.roles;
|
||||
},
|
||||
location({ state }){
|
||||
return state.location
|
||||
},
|
||||
displayName({ state }){
|
||||
return state.user;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user