1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #5695: Fix first subscription after login (#1842)

(cherry picked from commit 8affcb66a9a99359ba04f8205aba8ef0ab43fc51)
This commit is contained in:
Sergio Betanzos 2022-03-15 16:58:06 +01:00 committed by Tino Vazquez
parent 7e068a886a
commit 18bf9dcded

View File

@ -35,26 +35,32 @@ import { JWT_NAME } from 'client/constants'
const AuthLayout = ({ subscriptions = [], children }) => {
const dispatch = useDispatch()
const { changeJwt, stopFirstRender } = useAuthApi()
const { jwt, isLogged, isLoginInProgress, firstRender } = useAuth()
const { jwt, user, isLogged, isLoginInProgress, firstRender } = useAuth()
useEffect(() => {
if (!jwt) return
const endpoints = [
groupApi.endpoints.getGroups,
authApi.endpoints.getAuthUser,
...subscriptions,
].map((endpoint) =>
dispatch(endpoint.initiate(undefined, { forceRefetch: true }))
const authSubscription = dispatch(
authApi.endpoints.getAuthUser.initiate(undefined, { forceRefetch: true })
)
return authSubscription.unsubscribe
}, [dispatch, jwt])
useEffect(() => {
if (!jwt || !user?.NAME) return
const endpoints = [groupApi.endpoints.getGroups, ...subscriptions].map(
(endpoint) =>
dispatch(endpoint.initiate(undefined, { forceRefetch: true }))
)
return () => {
endpoints.forEach((endpoint) => {
endpoint.unsubscribe()
endpoint.abort()
})
}
}, [dispatch, jwt])
}, [dispatch, jwt, user?.NAME])
useEffect(() => {
if (!jwt) {