@campxdev/shared 1.8.36 → 1.8.37
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 +1 -1
- package/src/hooks/useAuth.ts +19 -12
package/package.json
CHANGED
package/src/hooks/useAuth.ts
CHANGED
|
@@ -33,17 +33,30 @@ const ApplicationObj = {
|
|
|
33
33
|
payments: 'payments',
|
|
34
34
|
exams: 'exams',
|
|
35
35
|
}
|
|
36
|
-
const checkIsAdmin = (user
|
|
37
|
-
let
|
|
36
|
+
const checkIsAdmin = (user) => {
|
|
37
|
+
let subDomain = window.location.host.split('.')?.slice(-3)[0]
|
|
38
|
+
const localSubDomain = process.env.REACT_APP_SUBDOMAIN
|
|
38
39
|
|
|
39
40
|
if (user?.isSuperuser) return 1
|
|
40
41
|
|
|
41
42
|
if (process.env.NODE_ENV === 'development') {
|
|
42
|
-
|
|
43
|
+
subDomain = localSubDomain
|
|
44
|
+
|
|
45
|
+
if (!localSubDomain) {
|
|
46
|
+
toast.warn('Subdomain not added in .env file')
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.log(
|
|
52
|
+
'Current App ->',
|
|
53
|
+
ApplicationObj[subDomain],
|
|
54
|
+
'; subdomain env ->',
|
|
55
|
+
subDomain,
|
|
56
|
+
)
|
|
57
|
+
|
|
45
58
|
const profile = user?.userProfile.find(
|
|
46
|
-
(item) => item.application ==
|
|
59
|
+
(item) => item.application == ApplicationObj[subDomain],
|
|
47
60
|
)
|
|
48
61
|
return profile ? (profile.isAdmin == true ? 1 : 0) : 0
|
|
49
62
|
}
|
|
@@ -88,14 +101,8 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
88
101
|
can_settings_view: 1,
|
|
89
102
|
can_dashboard_view: 1,
|
|
90
103
|
can_individual_pages_view: 1,
|
|
91
|
-
can_analatics_view: checkIsAdmin(
|
|
92
|
-
|
|
93
|
-
ApplicationObj[originSubdomain],
|
|
94
|
-
),
|
|
95
|
-
can_admin_view: checkIsAdmin(
|
|
96
|
-
res.data.user,
|
|
97
|
-
ApplicationObj[originSubdomain],
|
|
98
|
-
),
|
|
104
|
+
can_analatics_view: checkIsAdmin(res.data.user),
|
|
105
|
+
can_admin_view: checkIsAdmin(res.data.user),
|
|
99
106
|
} as any
|
|
100
107
|
s.applications = res.data?.applications ?? []
|
|
101
108
|
})
|