@campxdev/shared 1.11.7-0.alpha.51 → 1.11.7-0.alpha.52
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 +13 -34
package/package.json
CHANGED
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxiosError } from 'axios'
|
|
2
|
+
import Cookies from 'js-cookie'
|
|
2
3
|
import { useEffect, useState } from 'react'
|
|
4
|
+
import { useNavigate } from 'react-router-dom'
|
|
3
5
|
import { toast } from 'react-toastify'
|
|
4
6
|
import axios from '../config/axios'
|
|
5
7
|
import { isDevelopment } from '../constants'
|
|
@@ -102,12 +104,12 @@ const loginErrorHandler = ({
|
|
|
102
104
|
setLoading?: any
|
|
103
105
|
err: AxiosError
|
|
104
106
|
}) => {
|
|
107
|
+
const navigate = useNavigate()
|
|
105
108
|
setLoading && setLoading(false)
|
|
106
109
|
const origin = window.location.origin
|
|
107
110
|
const isStaging = origin.split('campx')[1] === '.dev'
|
|
108
|
-
const isSetup = window.location.hostname.split('.').includes('setup')
|
|
109
111
|
|
|
110
|
-
if (isDevelopment || isStaging
|
|
112
|
+
if (isDevelopment || isStaging) {
|
|
111
113
|
openRootModal({
|
|
112
114
|
key: 'login',
|
|
113
115
|
contentData: {
|
|
@@ -120,15 +122,7 @@ const loginErrorHandler = ({
|
|
|
120
122
|
})
|
|
121
123
|
return
|
|
122
124
|
} else {
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (err.response.status !== 401) {
|
|
127
|
-
if (err.response.status > 400 && err.response.status < 500) {
|
|
128
|
-
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
129
|
-
} else {
|
|
130
|
-
toast.error('Server Error')
|
|
131
|
-
}
|
|
125
|
+
navigate('/auth/login')
|
|
132
126
|
}
|
|
133
127
|
}
|
|
134
128
|
|
|
@@ -142,30 +136,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
142
136
|
axios
|
|
143
137
|
.get(permissionsEndpoint)
|
|
144
138
|
.then((res) => {
|
|
145
|
-
const origin = window.location.origin
|
|
146
|
-
const originSubdomain =
|
|
147
|
-
window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
|
|
148
|
-
const isStaging = origin.split('campx')[1] === '.dev'
|
|
149
139
|
const isAdmin = checkIsAdmin(res.data.user)
|
|
150
|
-
const isSetup =
|
|
151
|
-
window.location.hostname.split('.').includes('setup') && isAdmin
|
|
152
|
-
const isMasterSlave = res.data?.institutionType === 'MASTER_CHILD'
|
|
153
|
-
|
|
154
|
-
// eslint-disable-next-line no-console
|
|
155
|
-
|
|
156
|
-
if (isDevelopment == false && isStaging == false && !isSetup) {
|
|
157
|
-
if (
|
|
158
|
-
!res.data.applications.includes(ApplicationObj[originSubdomain])
|
|
159
|
-
) {
|
|
160
|
-
window.location.replace(
|
|
161
|
-
`https://www.id.campx.in/apps?redirect_to=${url}`,
|
|
162
|
-
)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (res.data?.institutions) {
|
|
167
|
-
handleInstitutions(res.data?.institutions)
|
|
168
|
-
}
|
|
169
140
|
|
|
170
141
|
setData(res.data)
|
|
171
142
|
UserStore.update((s) => {
|
|
@@ -198,6 +169,14 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
198
169
|
s.isMasterInstitution = res.data?.isMasterInstitution
|
|
199
170
|
s.isHomePageEnabled = res.data?.isHomePageEnabled
|
|
200
171
|
})
|
|
172
|
+
|
|
173
|
+
InstitutionsStore.update((s) => {
|
|
174
|
+
s.institutions = res.data?.institutions
|
|
175
|
+
s.current = res.data?.institutions.find(
|
|
176
|
+
(item) => item.code === Cookies.get('campx_institution'),
|
|
177
|
+
)
|
|
178
|
+
})
|
|
179
|
+
|
|
201
180
|
AssetsStore.update((s) => {
|
|
202
181
|
s.logo = res.data?.assets.logo
|
|
203
182
|
s.logo_square = res.data?.assets.logo_square
|