@eeplatform/nuxt-layer-common 1.2.1 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @eeplatform/nuxt-layer-common
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 49f4a58: Revise authentication implementation
8
+
3
9
  ## 1.2.1
4
10
 
5
11
  ### Patch Changes
@@ -30,19 +30,19 @@ export default function useLocal() {
30
30
  title: "School",
31
31
  icon: "ph:building-bold",
32
32
  link: APP_SCHOOL as string,
33
- landingPage: "home",
33
+ landingPage: "",
34
34
  },
35
35
  {
36
36
  title: "Division",
37
37
  icon: "ph:building-apartment-bold",
38
38
  link: APP_DIVISION as string,
39
- landingPage: "home",
39
+ landingPage: "",
40
40
  },
41
41
  {
42
42
  title: "Region",
43
43
  icon: "ph:buildings-bold",
44
44
  link: APP_REGION as string,
45
- landingPage: "home",
45
+ landingPage: "",
46
46
  },
47
47
  ];
48
48
  });
@@ -38,7 +38,7 @@ export default function useLocalAuth() {
38
38
  }
39
39
 
40
40
  async function login({ email = "", password = "", role = "" }) {
41
- return useNuxtApp().$api<TKeyValuePair>("/api/auth/login", {
41
+ return useNuxtApp().$api<Record<string, any>>("/api/auth/login", {
42
42
  method: "POST",
43
43
  body: JSON.stringify({ email, password, role }),
44
44
  });
@@ -78,19 +78,17 @@ export default function useLocalAuth() {
78
78
  }
79
79
  }
80
80
 
81
- async function getCurrentUser() {
81
+ function getCurrentUser() {
82
82
  const user = useCookie("user", cookieConfig).value;
83
- if (!user) return null;
84
- try {
85
- const _user = await useNuxtApp().$api<TUser>(`/api/users/id/${user}`, {
86
- method: "GET",
87
- });
83
+ const { data: userData } = useLazyAsyncData("get-current-user", () =>
84
+ useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
85
+ );
88
86
 
89
- currentUser.value = _user;
90
- return _user;
91
- } catch (error) {
92
- console.log("Error fetching current user:", error);
93
- }
87
+ watchEffect(() => {
88
+ if (userData.value) {
89
+ currentUser.value = userData.value;
90
+ }
91
+ });
94
92
  }
95
93
 
96
94
  async function forgotPassword(email: string) {
@@ -129,13 +127,13 @@ export default function useLocalAuth() {
129
127
  }
130
128
 
131
129
  function verify(id: string) {
132
- return useNuxtApp().$api<TKeyValuePair>(`/api/auth/verify/${id}`, {
130
+ return useNuxtApp().$api<Record<string, any>>(`/api/auth/verify/${id}`, {
133
131
  method: "GET",
134
132
  });
135
133
  }
136
134
 
137
135
  function signUp(email: string, referral: string) {
138
- return useNuxtApp().$api<TKeyValuePair>("/api/auth/sign-up", {
136
+ return useNuxtApp().$api<Record<string, any>>("/api/auth/sign-up", {
139
137
  method: "POST",
140
138
  body: { email, referral },
141
139
  });
@@ -1,14 +1,12 @@
1
1
  export function useLocalSetup(type: string, org?: string) {
2
- const { currentUser } = useLocalAuth();
3
-
4
- const userId = computed(() => currentUser.value?._id ?? "");
2
+ const userId = computed(() => useCookie("user").value ?? "");
5
3
 
6
4
  const { getByUserType } = useMember();
7
5
 
8
6
  const { data: userMemberData, error: userMemberError } = useLazyAsyncData(
9
7
  "get-member-by-id",
10
8
  () => getByUserType(userId.value, type, org),
11
- { watch: [userId], immediate: false }
9
+ { watch: [userId] }
12
10
  );
13
11
 
14
12
  watchEffect(() => {
@@ -40,7 +38,10 @@ export function useLocalSetup(type: string, org?: string) {
40
38
  }
41
39
  });
42
40
 
41
+ const id = computed(() => userMemberData.value?.org ?? "id");
42
+
43
43
  return {
44
44
  userAppRole,
45
+ id,
45
46
  };
46
47
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@eeplatform/nuxt-layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.2.1",
5
+ "version": "1.2.2",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"