@campxdev/shared 1.8.35 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.8.35",
3
+ "version": "1.8.37",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -4,7 +4,6 @@ import { toast } from 'react-toastify'
4
4
  import axios from '../config/axios'
5
5
  import { isDevelopment } from '../constants'
6
6
  import { useLoginForm } from '../contexts/LoginFormProvider'
7
- import { campxTenantKey, urlTenantKey } from '../contexts/Providers'
8
7
  import { PermissionsStore, AssetsStore, UserStore } from '../shared-state'
9
8
 
10
9
  const url = window.location.origin
@@ -34,10 +33,34 @@ const ApplicationObj = {
34
33
  payments: 'payments',
35
34
  exams: 'exams',
36
35
  }
37
- const checkIsAdmin = (userProfile, application) => {
38
- const profile = userProfile.find((item) => item.application == application)
36
+ const checkIsAdmin = (user) => {
37
+ let subDomain = window.location.host.split('.')?.slice(-3)[0]
38
+ const localSubDomain = process.env.REACT_APP_SUBDOMAIN
39
+
40
+ if (user?.isSuperuser) return 1
41
+
42
+ if (process.env.NODE_ENV === 'development') {
43
+ subDomain = localSubDomain
44
+
45
+ if (!localSubDomain) {
46
+ toast.warn('Subdomain not added in .env file')
47
+ }
48
+ }
49
+
50
+ // eslint-disable-next-line no-console
51
+ console.log(
52
+ 'Current App ->',
53
+ ApplicationObj[subDomain],
54
+ '; subdomain env ->',
55
+ subDomain,
56
+ )
57
+
58
+ const profile = user?.userProfile.find(
59
+ (item) => item.application == ApplicationObj[subDomain],
60
+ )
39
61
  return profile ? (profile.isAdmin == true ? 1 : 0) : 0
40
62
  }
63
+
41
64
  function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
42
65
  const { openLoginForm } = useLoginForm()
43
66
  const [loading, setLoading] = useState<boolean>(false)
@@ -78,14 +101,8 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
78
101
  can_settings_view: 1,
79
102
  can_dashboard_view: 1,
80
103
  can_individual_pages_view: 1,
81
- can_analatics_view: checkIsAdmin(
82
- res.data.user.profiles,
83
- ApplicationObj[originSubdomain],
84
- ),
85
- can_admin_view: checkIsAdmin(
86
- res.data.user.profiles,
87
- ApplicationObj[originSubdomain],
88
- ),
104
+ can_analatics_view: checkIsAdmin(res.data.user),
105
+ can_admin_view: checkIsAdmin(res.data.user),
89
106
  } as any
90
107
  s.applications = res.data?.applications ?? []
91
108
  })