From 76c8613556dcd1ffa9ee6ca6e31659a242db29db Mon Sep 17 00:00:00 2001 From: Stefan Petrov <106827257+stefan-petrov1@users.noreply.github.com> Date: Sun, 21 Apr 2024 06:43:35 +0300 Subject: [PATCH] Finish oauth with google --- client/src/App.tsx | 17 ++++++++++++++--- .../auth/protected-route/ProtectedRoute.tsx | 8 +++++++- client/src/pages/auth/register/Register.tsx | 10 +++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 000e09c..48323ba 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -52,7 +52,20 @@ function App() { } /> - {/* Only logged users */} + {/* Only logged users AND finished OAuth2*/} + + }> + } /> + } /> + + + {/* Only logged users with or without finished OAuth2*/} @@ -61,9 +74,7 @@ function App() { path={PageEnum.FinishRegister} element={} /> - } /> } /> - } /> {/* Only organisations */} diff --git a/client/src/components/auth/protected-route/ProtectedRoute.tsx b/client/src/components/auth/protected-route/ProtectedRoute.tsx index f210619..40fc979 100644 --- a/client/src/components/auth/protected-route/ProtectedRoute.tsx +++ b/client/src/components/auth/protected-route/ProtectedRoute.tsx @@ -6,6 +6,7 @@ import { PageEnum, RoleEnum } from '../../../types'; type ProtectedRouteProps = { role: RoleEnum | null; onlyAuth?: boolean; + blockNotFinishedOAuth?: boolean; }; // The component that protects a route based on the user data @@ -13,8 +14,9 @@ type ProtectedRouteProps = { export default function ProtectedRoute({ role, onlyAuth, + blockNotFinishedOAuth, }: ProtectedRouteProps) { - const { user, isOrganisation, isAuthenticated } = useAuthContext(); + const { user, isAuthenticated, hasFinishedOAuth2 } = useAuthContext(); const { pathname } = useLocation(); // Attach redirectTo search param @@ -38,6 +40,10 @@ export default function ProtectedRoute({ (role === user.role && isAuthenticated) || (onlyAuth && isAuthenticated); + if (passThrough && blockNotFinishedOAuth && !hasFinishedOAuth2) { + return ; + } + if (!user.role && !passThrough && pathname !== PageEnum.Logout) { return ; } diff --git a/client/src/pages/auth/register/Register.tsx b/client/src/pages/auth/register/Register.tsx index ff83900..ec97b7b 100644 --- a/client/src/pages/auth/register/Register.tsx +++ b/client/src/pages/auth/register/Register.tsx @@ -7,7 +7,7 @@ import FormInput from '../../../components/form-input/FormInput'; import SkillsSelect, { SkillOption, } from '../../../components/skills-select/SkillsSelect'; -import { authPaths, skillsPaths } from '../../../config/api'; +import { authPaths, OAuthPaths, skillsPaths } from '../../../config/api'; import { useErrorContext } from '../../../contexts/ErrorContext'; import useValidators from '../../../hooks/useValidator'; import { AlertTypeEnum, IAuthResponse, ISkill, RoleEnum } from '../../../types'; @@ -319,12 +319,12 @@ function Register() {
- +