From dbac74121a1a3838a16afe19e837be17660c1e74 Mon Sep 17 00:00:00 2001 From: Lucas Susin <lssusin@gmail.com> Date: Fri, 22 Oct 2021 16:13:02 -0300 Subject: [PATCH] Erro de UI flickering nas rotas protegidas corrigido --- src/context/hooks/route.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/context/hooks/route.tsx b/src/context/hooks/route.tsx index e4d342e..d989a2d 100644 --- a/src/context/hooks/route.tsx +++ b/src/context/hooks/route.tsx @@ -9,12 +9,16 @@ export function withPublic(Component: any) { const pathname = router.pathname; useEffect(() => { - if (auth.user) { + if(auth.user) { router.push('/admin'); } }); - return <Component auth={auth} pathname={pathname} {...props} />; + if(auth.user) { + return <h1 className="ant-message">Loading...</h1>; + } else { + return <Component auth={auth} pathname={pathname} {...props} />; + } }; } @@ -30,6 +34,10 @@ export function withProtected(Component: any) { } }); - return <Component auth={auth} pathname={pathname} {...props} />; + if(!auth.user) { + return <h1 className="ant-message">Loading...</h1>; + } else { + return <Component auth={auth} pathname={pathname} {...props} />; + } }; } -- GitLab