@campxdev/shared 1.8.37 → 1.8.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.8.37",
3
+ "version": "1.8.38",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -33,6 +33,7 @@ const ApplicationObj = {
33
33
  payments: 'payments',
34
34
  exams: 'exams',
35
35
  }
36
+
36
37
  const checkIsAdmin = (user) => {
37
38
  let subDomain = window.location.host.split('.')?.slice(-3)[0]
38
39
  const localSubDomain = process.env.REACT_APP_SUBDOMAIN
@@ -43,7 +44,7 @@ const checkIsAdmin = (user) => {
43
44
  subDomain = localSubDomain
44
45
 
45
46
  if (!localSubDomain) {
46
- toast.warn('Subdomain not added in .env file')
47
+ toast.warn('missing REACT_APP_SUBDOMAIN in .env')
47
48
  }
48
49
  }
49
50
 
@@ -55,7 +56,7 @@ const checkIsAdmin = (user) => {
55
56
  subDomain,
56
57
  )
57
58
 
58
- const profile = user?.userProfile.find(
59
+ const profile = user?.profiles?.find(
59
60
  (item) => item.application == ApplicationObj[subDomain],
60
61
  )
61
62
  return profile ? (profile.isAdmin == true ? 1 : 0) : 0
@@ -94,6 +95,9 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
94
95
  s.user = res.data?.user
95
96
  s.roles = res.data?.roles
96
97
  })
98
+ const isAdmin = checkIsAdmin(res.data.user)
99
+ // eslint-disable-next-line no-console
100
+ console.log('Is Admin -> ', isAdmin)
97
101
 
98
102
  PermissionsStore.update((s) => {
99
103
  s.permissions = {
@@ -101,8 +105,8 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
101
105
  can_settings_view: 1,
102
106
  can_dashboard_view: 1,
103
107
  can_individual_pages_view: 1,
104
- can_analatics_view: checkIsAdmin(res.data.user),
105
- can_admin_view: checkIsAdmin(res.data.user),
108
+ can_analatics_view: isAdmin,
109
+ can_admin_view: isAdmin,
106
110
  } as any
107
111
  s.applications = res.data?.applications ?? []
108
112
  })