From 12c298b9a0ce91af33fcb7fe8d65ddbd2ef7c815 Mon Sep 17 00:00:00 2001 From: Dell Date: Thu, 26 May 2022 11:38:45 +0700 Subject: [PATCH] Fix Authentication --- .../src/contexts/LaravelAuthContext.tsx | 8 ++---- .../client-portal/src/guards/AuthGuard.tsx | 2 +- .../client-portal/src/guards/GuestGuard.tsx | 2 +- frontend/client-portal/src/routes/index.tsx | 28 +++++++++++++------ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/frontend/client-portal/src/contexts/LaravelAuthContext.tsx b/frontend/client-portal/src/contexts/LaravelAuthContext.tsx index 8e789f19..d30559b5 100644 --- a/frontend/client-portal/src/contexts/LaravelAuthContext.tsx +++ b/frontend/client-portal/src/contexts/LaravelAuthContext.tsx @@ -87,7 +87,8 @@ function AuthProvider({ children }: AuthProviderProps) { console.log('initialize', state) try { const accessToken = getSession(); - + + console.log('') if (accessToken) { setSession(accessToken); @@ -111,7 +112,6 @@ function AuthProvider({ children }: AuthProviderProps) { }); } } catch (err) { - console.error(err); dispatch({ type: Types.Initial, payload: { @@ -124,7 +124,6 @@ function AuthProvider({ children }: AuthProviderProps) { initialize(); }, []); - // const csrf = () => axios.get('/sanctum/csrf-cookie') const login = async (email: string, password: string) => { return axios @@ -169,8 +168,7 @@ function AuthProvider({ children }: AuthProviderProps) { dispatch({ type: Types.Logout }); }; - return ( - ; + return ; } if (requestedLocation && pathname !== requestedLocation) { diff --git a/frontend/client-portal/src/guards/GuestGuard.tsx b/frontend/client-portal/src/guards/GuestGuard.tsx index 3b301485..feb464cb 100644 --- a/frontend/client-portal/src/guards/GuestGuard.tsx +++ b/frontend/client-portal/src/guards/GuestGuard.tsx @@ -15,7 +15,7 @@ export default function GuestGuard({ children }: GuestGuardProps) { const { isAuthenticated } = useAuth(); if (isAuthenticated) { - return ; + return ; } return <>{children}; diff --git a/frontend/client-portal/src/routes/index.tsx b/frontend/client-portal/src/routes/index.tsx index 951347eb..03466daf 100644 --- a/frontend/client-portal/src/routes/index.tsx +++ b/frontend/client-portal/src/routes/index.tsx @@ -11,6 +11,7 @@ import Register from '../pages/auth/Register'; import ResetPassword from '../pages/auth/ResetPassword'; import VerifyCode from '../pages/auth/VerifyCode'; import { AuthProvider } from '../contexts/LaravelAuthContext'; +import AuthGuard from '../guards/AuthGuard'; // ---------------------------------------------------------------------- @@ -34,22 +35,26 @@ export default function Router() { path: 'login', element: ( - + + + ), }, { path: 'register', element: ( - - - + + + + + ), }, - { path: 'login-unprotected', element: }, - { path: 'register-unprotected', element: }, - { path: 'reset-password', element: }, - { path: 'verify', element: }, + // { path: 'login-unprotected', element: }, + // { path: 'register-unprotected', element: }, + // { path: 'reset-password', element: }, + // { path: 'verify', element: }, ], }, // { @@ -58,7 +63,12 @@ export default function Router() { // }, { path: '/', - element: , + element: ( + + + + + ), children:[ { path: 'dashboard',