@7365admin1/layer-common 3.2.1-staging.72 → 3.2.1-staging.73

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.
@@ -588,7 +588,7 @@
588
588
  :org="orgId"
589
589
  :site="siteId"
590
590
  :visitor-data="selectedVisitorDataObject"
591
- :current-user="currentUser._id"
591
+ :current-user="currentUser?._id"
592
592
  :type="activeVisitorFormType"
593
593
  :enable-unregistered="enableUnregistered"
594
594
  @back="handleClickBack"
@@ -1,36 +1,7 @@
1
1
  export default function useLocalAuth() {
2
2
  const { cookieConfig } = useRuntimeConfig().public;
3
3
 
4
- const _address = {
5
- country: "",
6
- address1: "",
7
- address2: "",
8
- city: "",
9
- province: "",
10
- postalCode: "",
11
- };
12
-
13
- const user = {
14
- _id: "",
15
- givenName: "",
16
- middleName: "",
17
- surname: "",
18
- address: _address,
19
- email: "",
20
- password: "",
21
- type: "",
22
- createdAt: "",
23
- organization: "",
24
- role: "",
25
- primaryPhone: "",
26
- mobilePhone: "",
27
- serviceProviders: [],
28
- };
29
-
30
- const currentUser = useState(
31
- "currentUser",
32
- (): TUser | null => JSON.parse(JSON.stringify(user))
33
- );
4
+ const currentUser = useState<TUser | null>("currentUser", () => null);
34
5
 
35
6
  async function authenticate() {
36
7
  const user = useCookie("user", cookieConfig).value;
@@ -41,9 +12,7 @@ export default function useLocalAuth() {
41
12
  );
42
13
 
43
14
  watchEffect(() => {
44
- if (getCurrentUserReq.value) {
45
- currentUser.value = getCurrentUserReq.value as TUser;
46
- }
15
+ currentUser.value = (getCurrentUserReq.value as TUser | null) ?? null;
47
16
  });
48
17
 
49
18
  watchEffect(() => {
@@ -70,6 +39,7 @@ export default function useLocalAuth() {
70
39
  useCookie("sid", cookieConfig).value = null;
71
40
  useCookie("user", cookieConfig).value = null;
72
41
  useCookie("organization", cookieConfig).value = null;
42
+ currentUser.value = null;
73
43
  }
74
44
 
75
45
  async function logout() {
@@ -79,17 +49,20 @@ export default function useLocalAuth() {
79
49
  await useNuxtApp().$api(`/api/auth/${sid}`, {
80
50
  method: "DELETE",
81
51
  });
82
-
83
- clearCookies();
84
52
  } catch (error) {
85
53
  console.error("Logout failed:", error);
86
54
  }
55
+
56
+ clearCookies();
87
57
  }
88
58
  }
89
59
 
90
60
  async function getCurrentUser() {
91
61
  const user = useCookie("user", cookieConfig).value;
92
- if (!user) return null;
62
+ if (!user) {
63
+ currentUser.value = null;
64
+ return null;
65
+ }
93
66
  const _user = await useNuxtApp().$api<TUser>(`/api/users/id/${user}`, {
94
67
  method: "GET",
95
68
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "3.2.1-staging.72",
5
+ "version": "3.2.1-staging.73",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {