mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
🐛(frontend) fix app shallow reload
The app was doing a shallow reload when user was coming from another tab and the user data was staled. We stop to block the app during the loading state, depend the response the app will manage correctly its states.
This commit is contained in:
parent
3cc9655574
commit
e39b03c272
4 changed files with 17 additions and 10 deletions
|
|
@ -17,6 +17,7 @@ and this project adheres to
|
||||||
- 🚸(frontend) redirect on current url tab after 401 #2197
|
- 🚸(frontend) redirect on current url tab after 401 #2197
|
||||||
- 🐛(frontend) abort check media status unmount #2194
|
- 🐛(frontend) abort check media status unmount #2194
|
||||||
- ✨(backend) order pinned documents by last updated at #2028
|
- ✨(backend) order pinned documents by last updated at #2028
|
||||||
|
- 🐛(frontend) fix app shallow reload #2231
|
||||||
- 🐛(frontend) fix interlinking modal clipping #2213
|
- 🐛(frontend) fix interlinking modal clipping #2213
|
||||||
- 🛂(frontend) fix cannot manage member on small screen #2226
|
- 🛂(frontend) fix cannot manage member on small screen #2226
|
||||||
- 🐛(backend) load jwks url when OIDC_RS_PRIVATE_KEY_STR is set
|
- 🐛(backend) load jwks url when OIDC_RS_PRIVATE_KEY_STR is set
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ test.describe('Doc Create', () => {
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it creates a doc with link "/doc/new/', async ({
|
test('it creates a doc with link "/docs/new/"', async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
browserName,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
|
||||||
|
|
@ -18,32 +18,30 @@ import { FirstConnection } from './FirstConnection';
|
||||||
|
|
||||||
export const Auth = ({ children }: PropsWithChildren) => {
|
export const Auth = ({ children }: PropsWithChildren) => {
|
||||||
const {
|
const {
|
||||||
isLoading: isAuthLoading,
|
isAuthLoading,
|
||||||
pathAllowed,
|
pathAllowed,
|
||||||
isFetchedAfterMount,
|
|
||||||
authenticated,
|
authenticated,
|
||||||
fetchStatus,
|
hasInitiallyLoaded,
|
||||||
user,
|
user,
|
||||||
} = useAuth();
|
} = useAuth();
|
||||||
const isLoading = fetchStatus !== 'idle' || isAuthLoading;
|
|
||||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||||
const { data: config } = useConfig();
|
const { data: config } = useConfig();
|
||||||
const shouldTrySilentLogin = useMemo(
|
const shouldTrySilentLogin = useMemo(
|
||||||
() =>
|
() =>
|
||||||
!authenticated &&
|
!authenticated &&
|
||||||
!hasTrySilent() &&
|
!hasTrySilent() &&
|
||||||
!isLoading &&
|
!isAuthLoading &&
|
||||||
!isRedirecting &&
|
!isRedirecting &&
|
||||||
config?.FRONTEND_SILENT_LOGIN_ENABLED,
|
config?.FRONTEND_SILENT_LOGIN_ENABLED,
|
||||||
[
|
[
|
||||||
authenticated,
|
authenticated,
|
||||||
isLoading,
|
isAuthLoading,
|
||||||
isRedirecting,
|
isRedirecting,
|
||||||
config?.FRONTEND_SILENT_LOGIN_ENABLED,
|
config?.FRONTEND_SILENT_LOGIN_ENABLED,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
const shouldTryLogin =
|
const shouldTryLogin =
|
||||||
!authenticated && !isLoading && !isRedirecting && !pathAllowed;
|
!authenticated && !isAuthLoading && !isRedirecting && !pathAllowed;
|
||||||
const { replace, pathname } = useRouter();
|
const { replace, pathname } = useRouter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,7 +102,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const shouldShowLoader =
|
const shouldShowLoader =
|
||||||
(isLoading && !isFetchedAfterMount) ||
|
!hasInitiallyLoaded ||
|
||||||
isRedirecting ||
|
isRedirecting ||
|
||||||
(!authenticated && !pathAllowed) ||
|
(!authenticated && !pathAllowed) ||
|
||||||
shouldTrySilentLogin;
|
shouldTrySilentLogin;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { useAnalytics } from '@/libs';
|
import { useAnalytics } from '@/libs';
|
||||||
|
|
||||||
|
|
@ -12,6 +12,12 @@ export const useAuth = () => {
|
||||||
const { pathname } = useRouter();
|
const { pathname } = useRouter();
|
||||||
const { trackEvent } = useAnalytics();
|
const { trackEvent } = useAnalytics();
|
||||||
const [hasTracked, setHasTracked] = useState(authStates.isFetched);
|
const [hasTracked, setHasTracked] = useState(authStates.isFetched);
|
||||||
|
const isAuthLoading =
|
||||||
|
authStates.fetchStatus !== 'idle' || authStates.isLoading;
|
||||||
|
const hasInitiallyLoaded = useRef(false);
|
||||||
|
if (authStates.isFetched) {
|
||||||
|
hasInitiallyLoaded.current = true;
|
||||||
|
}
|
||||||
const [pathAllowed, setPathAllowed] = useState<boolean>(
|
const [pathAllowed, setPathAllowed] = useState<boolean>(
|
||||||
!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)),
|
!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)),
|
||||||
);
|
);
|
||||||
|
|
@ -35,6 +41,8 @@ export const useAuth = () => {
|
||||||
user,
|
user,
|
||||||
authenticated: !!user && authStates.isSuccess,
|
authenticated: !!user && authStates.isSuccess,
|
||||||
pathAllowed,
|
pathAllowed,
|
||||||
|
hasInitiallyLoaded: hasInitiallyLoaded.current,
|
||||||
|
isAuthLoading,
|
||||||
...authStates,
|
...authStates,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue