mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-22 18:49:18 +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: '',
|
token: '',
|
||||||
user: {},
|
user: {},
|
||||||
roles: [],
|
roles: [],
|
||||||
|
location: {},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async setBasicData({ dispatch }, { token, user, roles }){
|
async setBasicData({ dispatch }, { token, user, roles, location }){
|
||||||
await localForage.setItem('user', user);
|
await localForage.setItem('user', user);
|
||||||
await localForage.setItem('token', token);
|
await localForage.setItem('token', token);
|
||||||
await localForage.setItem('roles', roles);
|
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 }){
|
async getBasicData({ dispatch }){
|
||||||
const result = {
|
const result = {
|
||||||
user: await localForage.getItem('user'),
|
user: await localForage.getItem('user'),
|
||||||
token: await localForage.getItem('token'),
|
token: await localForage.getItem('token'),
|
||||||
roles: await localForage.getItem('roles'),
|
roles: await localForage.getItem('roles'),
|
||||||
|
location: await localForage.getItem('location'),
|
||||||
}
|
}
|
||||||
dispatch('auth_success', result);
|
dispatch('auth_success', result);
|
||||||
},
|
},
|
||||||
async clearBasicData(){
|
async clearBasicData(){
|
||||||
await localForage.removeItem('user');
|
await localForage.deleteItem('user');
|
||||||
await localForage.removeItem('token');
|
await localForage.deleteItem('token');
|
||||||
await localForage.removeItem('roles');
|
await localForage.deleteItem('roles');
|
||||||
|
await localForage.deleteItem('location');
|
||||||
},
|
},
|
||||||
async checkData({ dispatch }){
|
async checkData({ dispatch }){
|
||||||
let token = await localForage.getItem('token');
|
let token = await localForage.getItem('token');
|
||||||
@ -44,9 +48,11 @@ const user = createStore({
|
|||||||
|
|
||||||
delete response.data.token;
|
delete response.data.token;
|
||||||
delete response.data.roles;
|
delete response.data.roles;
|
||||||
|
delete response.data.location;
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
dispatch('auth_error');
|
dispatch('auth_error');
|
||||||
await clearBasicData();
|
await clearBasicData();
|
||||||
throw new error;
|
throw new error;
|
||||||
@ -63,15 +69,17 @@ const user = createStore({
|
|||||||
state.token = '';
|
state.token = '';
|
||||||
state.user = {};
|
state.user = {};
|
||||||
state.roles = [];
|
state.roles = [];
|
||||||
|
state.location = {};
|
||||||
},
|
},
|
||||||
auth_request({ state }){
|
auth_request({ state }){
|
||||||
state.status = 'loading';
|
state.status = 'loading';
|
||||||
},
|
},
|
||||||
auth_success({ state }, { token, user, roles }){
|
auth_success({ state }, { token, user, roles, location }){
|
||||||
state.status = 'success';
|
state.status = 'success';
|
||||||
state.token = token;
|
state.token = token;
|
||||||
state.user = user;
|
state.user = user;
|
||||||
state.roles = roles;
|
state.roles = roles;
|
||||||
|
state.location = location;
|
||||||
},
|
},
|
||||||
auth_error({ state }){
|
auth_error({ state }){
|
||||||
state.status = 'error'
|
state.status = 'error'
|
||||||
@ -91,6 +99,9 @@ const user = createStore({
|
|||||||
roles({ state }){
|
roles({ state }){
|
||||||
return state.roles;
|
return state.roles;
|
||||||
},
|
},
|
||||||
|
location({ state }){
|
||||||
|
return state.location
|
||||||
|
},
|
||||||
displayName({ state }){
|
displayName({ state }){
|
||||||
return state.user;
|
return state.user;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user