@fy-/fws-vue 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +7 -1
- package/package.json +1 -1
- package/stores/user.ts +29 -0
package/index.ts
CHANGED
|
@@ -11,7 +11,12 @@ import {
|
|
|
11
11
|
isServerRendered,
|
|
12
12
|
} from "./composables/ssr";
|
|
13
13
|
import { useSeo } from "./composables/seo";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
useUserStore,
|
|
16
|
+
useUserCheck,
|
|
17
|
+
useUserCheckAsync,
|
|
18
|
+
useUserCheckAsyncSimple,
|
|
19
|
+
} from "./stores/user";
|
|
15
20
|
import { ClientOnly } from "./components/ssr/ClientOnly";
|
|
16
21
|
import {
|
|
17
22
|
cropText,
|
|
@@ -115,6 +120,7 @@ export {
|
|
|
115
120
|
useUserCheck,
|
|
116
121
|
useUserCheckAsync,
|
|
117
122
|
useRest,
|
|
123
|
+
useUserCheckAsyncSimple,
|
|
118
124
|
|
|
119
125
|
// Components
|
|
120
126
|
// UI/Transitions
|
package/package.json
CHANGED
package/stores/user.ts
CHANGED
|
@@ -48,6 +48,35 @@ export const useUserStore = defineStore({
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
export async function useUserCheckAsyncSimple(
|
|
52
|
+
path = "/login",
|
|
53
|
+
redirectLink = false,
|
|
54
|
+
) {
|
|
55
|
+
const userStore = useUserStore();
|
|
56
|
+
await userStore.refreshUser();
|
|
57
|
+
const isAuth = computed(() => userStore.isAuth);
|
|
58
|
+
const router = useServerRouter();
|
|
59
|
+
|
|
60
|
+
const checkUser = (route: RouteLocation) => {
|
|
61
|
+
if (route.meta.reqLogin) {
|
|
62
|
+
if (!isAuth.value) {
|
|
63
|
+
if (!redirectLink) router.push(path);
|
|
64
|
+
else {
|
|
65
|
+
router.status = 307;
|
|
66
|
+
router.push(`${path}?return_to=${route.path}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
checkUser(router.currentRoute);
|
|
72
|
+
|
|
73
|
+
router._router.beforeEach((to: any) => {
|
|
74
|
+
if (to.fullPath != path) {
|
|
75
|
+
checkUser(to);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
51
80
|
export async function useUserCheckAsync(path = "/login", redirectLink = false) {
|
|
52
81
|
const userStore = useUserStore();
|
|
53
82
|
await userStore.refreshUser();
|