@campxdev/shared 1.8.32 → 1.8.33

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.32",
3
+ "version": "1.8.33",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -28,6 +28,16 @@ type AuthResponse = {
28
28
  }
29
29
  }
30
30
 
31
+ const ApplicationObj = {
32
+ enroll: 'enroll_x',
33
+ ums: 'square',
34
+ payments: 'payments',
35
+ exams: 'exams',
36
+ }
37
+ const checkIsAdmin = (userProfile, application) => {
38
+ const profile = userProfile.find((item) => item.application == application)
39
+ return profile ? profile.isAdmin : false
40
+ }
31
41
  function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
32
42
  const { openLoginForm } = useLoginForm()
33
43
  const [loading, setLoading] = useState<boolean>(false)
@@ -39,12 +49,15 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
39
49
  .get(permissionsEndpoint)
40
50
  .then((res) => {
41
51
  const origin = window.location.origin
42
- const domain = origin.split('campx')[0].split('//')[1]
52
+ const originSubdomain =
53
+ window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
43
54
 
44
55
  const isStaging = origin.split('campx')[1] === '.dev'
45
56
 
46
57
  if (isDevelopment == false && isStaging == false) {
47
- if (!res.data.applications.includes(domain)) {
58
+ if (
59
+ !res.data.applications.includes(ApplicationObj[originSubdomain])
60
+ ) {
48
61
  window.location.replace(
49
62
  `https://www.id.campx.in/apps?redirect_to=${url}`,
50
63
  )