Skip to content

Commit c450d20

Browse files
committed
Fixed multicall for fetchUser and moved it to userstore
1 parent 0a86190 commit c450d20

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

resources/js/App.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
} from 'vue-final-modal';
2525
2626
import useSystemStore from '@/bootstrap/stores/system.js';
27+
import useUserStore from './bootstrap/stores/user';
28+
2729
import { useI18n } from 'vue-i18n';
2830
import { provideToast, useToast } from '@/plugins/toast.js';
2931
@@ -38,6 +40,7 @@
3840
setup(props) {
3941
const { t } = useI18n();
4042
const systemStore = useSystemStore();
43+
const userStore = useUserStore();
4144
4245
// FETCH
4346
@@ -49,8 +52,7 @@
4952
// ON MOUNTED
5053
onMounted(async _ => {
5154
try {
52-
await systemStore.checkAuthState();
53-
await systemStore.setUser();
55+
await userStore.checkAuth();
5456
} catch(e) {
5557
if(e.response.status == 401) {
5658
systemStore.setAppState(true);

resources/js/bootstrap/stores/system.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import useUserStore from './user.js';
1212
import {
1313
checkAccess,
1414
fetchPreData,
15-
fetchUser,
1615
searchConceptSelection,
1716
uploadPlugin,
1817
installPlugin,
@@ -149,9 +148,6 @@ export const useSystemStore = defineStore('system', {
149148

150149
this.pluginStores[id] = defineStore(`plugin_${id}`, store);
151150
},
152-
async checkAuthState() {
153-
return await fetchUser();
154-
},
155151
async checkAccess(route) {
156152
const accessResponse = await checkAccess(route);
157153
if(accessResponse.status == 200 && accessResponse?.data?.redirect) {
@@ -161,15 +157,6 @@ export const useSystemStore = defineStore('system', {
161157

162158
return true;
163159
},
164-
async setUser() {
165-
const userStore = useUserStore();
166-
167-
const userData = await fetchUser();
168-
169-
const loginSuccessful = userData.status == 'success';
170-
userStore.setLoginState(loginSuccessful);
171-
userStore.setActiveUser(loginSuccessful ? userData.data : {});
172-
},
173160
async initialize(locale) {
174161
resetState(this);
175162

resources/js/bootstrap/stores/user.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
patchRoleData,
1717
reactivateUser,
1818
setUserAvatar,
19+
fetchUser,
1920
} from '@/api.js';
2021

2122
import {
@@ -137,6 +138,15 @@ export const useUserStore = defineStore('user', {
137138
},
138139
},
139140
actions: {
141+
async checkAuth(){
142+
try{
143+
const user = await fetchUser()
144+
this.setActiveUser(user)
145+
return user
146+
} catch {
147+
return null;
148+
}
149+
},
140150
setLoginState(value) {
141151
this.userLoggedIn = value;
142152
},

0 commit comments

Comments
 (0)