From 6b871da1432e76153c18e25487d3c820b640f3c4 Mon Sep 17 00:00:00 2001 From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it> Date: Sat, 5 Jun 2021 09:05:49 +0200 Subject: [PATCH] Fetch role only when promise ran. --- src/components/Auth/ChoseRole/ChoseRole.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Auth/ChoseRole/ChoseRole.tsx b/src/components/Auth/ChoseRole/ChoseRole.tsx index 334e2bb..558f33a 100644 --- a/src/components/Auth/ChoseRole/ChoseRole.tsx +++ b/src/components/Auth/ChoseRole/ChoseRole.tsx @@ -5,6 +5,7 @@ import { setRole } from 'api/setRole'; import { useHistory } from 'react-router-dom'; import { AuthRoutes } from 'api/routes'; import { AuthContext } from 'components/Auth/AuthContext'; +import { getRole } from 'api/getRole'; /** * Page that let's users decide role between available roles. @@ -17,11 +18,10 @@ export const ChoseRole: FC = () => { const { setIsAuth } = useContext(AuthContext); const choseAndForward = (role: string): void => { - // Set role in the server. - setRole(role); setIsAuth(true); - // Push to homepage. - history.push(`${AuthRoutes.dashboard}${AuthRoutes.home}`); + setRole(role).then(() => + history.push(`${AuthRoutes.dashboard}${AuthRoutes.home}`), + ); }; useEffect(() => { -- GitLab