@fy-/fws-vue 0.3.75 → 0.3.77

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 CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  isServerRendered,
12
12
  } from "./composables/ssr";
13
13
  import { useSeo } from "./composables/seo";
14
- import { useUserStore, useUserCheck } from "./stores/user";
14
+ import { useUserStore, useUserCheck, useUserCheckAsync } from "./stores/user";
15
15
  import { ClientOnly } from "./components/ssr/ClientOnly";
16
16
  import {
17
17
  cropText,
@@ -110,6 +110,7 @@ export {
110
110
  useSeo,
111
111
  useUserStore,
112
112
  useUserCheck,
113
+ useUserCheckAsync,
113
114
  useRest,
114
115
 
115
116
  // Components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "0.3.75",
3
+ "version": "0.3.77",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {
package/stores/user.ts CHANGED
@@ -47,6 +47,34 @@ export const useUserStore = defineStore({
47
47
  },
48
48
  });
49
49
 
50
+ export async function useUserCheckAsync(path = "/login", redirectLink = false) {
51
+ const userStore = useUserStore();
52
+ await userStore.refreshUser();
53
+ const isAuth = computed(() => userStore.isAuth);
54
+ const router = useServerRouter();
55
+
56
+ const checkUser = (route: RouteLocation) => {
57
+ if (route.meta.reqLogin) {
58
+ if (!isAuth.value) {
59
+ if (!redirectLink) router.push(path);
60
+ else {
61
+ router.status = 307;
62
+ router.push(`${path}?return_to=${route.path}`);
63
+ }
64
+ }
65
+ }
66
+ };
67
+
68
+ router._router.afterEach(async () => {
69
+ await userStore.refreshUser();
70
+ });
71
+ router._router.beforeEach((to: any) => {
72
+ if (to.fullPath != path) {
73
+ checkUser(to);
74
+ }
75
+ });
76
+ }
77
+
50
78
  export function useUserCheck(path = "/login", redirectLink = false) {
51
79
  const userStore = useUserStore();
52
80
  const isAuth = computed(() => userStore.isAuth);