@campxdev/shared 1.8.36 → 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.36",
3
+ "version": "1.8.38",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -33,17 +33,31 @@ const ApplicationObj = {
33
33
  payments: 'payments',
34
34
  exams: 'exams',
35
35
  }
36
- const checkIsAdmin = (user, subDomain) => {
37
- let currentApp = subDomain
36
+
37
+ const checkIsAdmin = (user) => {
38
+ let subDomain = window.location.host.split('.')?.slice(-3)[0]
39
+ const localSubDomain = process.env.REACT_APP_SUBDOMAIN
38
40
 
39
41
  if (user?.isSuperuser) return 1
40
42
 
41
43
  if (process.env.NODE_ENV === 'development') {
42
- currentApp = ApplicationObj[process.env.REACT_APP_SUBDOMAIN]
44
+ subDomain = localSubDomain
45
+
46
+ if (!localSubDomain) {
47
+ toast.warn('missing REACT_APP_SUBDOMAIN in .env')
48
+ }
43
49
  }
44
50
 
45
- const profile = user?.userProfile.find(
46
- (item) => item.application == currentApp,
51
+ // eslint-disable-next-line no-console
52
+ console.log(
53
+ 'Current App ->',
54
+ ApplicationObj[subDomain],
55
+ '; subdomain env ->',
56
+ subDomain,
57
+ )
58
+
59
+ const profile = user?.profiles?.find(
60
+ (item) => item.application == ApplicationObj[subDomain],
47
61
  )
48
62
  return profile ? (profile.isAdmin == true ? 1 : 0) : 0
49
63
  }
@@ -81,6 +95,9 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
81
95
  s.user = res.data?.user
82
96
  s.roles = res.data?.roles
83
97
  })
98
+ const isAdmin = checkIsAdmin(res.data.user)
99
+ // eslint-disable-next-line no-console
100
+ console.log('Is Admin -> ', isAdmin)
84
101
 
85
102
  PermissionsStore.update((s) => {
86
103
  s.permissions = {
@@ -88,14 +105,8 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
88
105
  can_settings_view: 1,
89
106
  can_dashboard_view: 1,
90
107
  can_individual_pages_view: 1,
91
- can_analatics_view: checkIsAdmin(
92
- res.data.user.profiles,
93
- ApplicationObj[originSubdomain],
94
- ),
95
- can_admin_view: checkIsAdmin(
96
- res.data.user,
97
- ApplicationObj[originSubdomain],
98
- ),
108
+ can_analatics_view: isAdmin,
109
+ can_admin_view: isAdmin,
99
110
  } as any
100
111
  s.applications = res.data?.applications ?? []
101
112
  })