diff --git a/frontend/src/components/Navbar.js b/frontend/src/components/Navbar.js index e454d50..16e695d 100644 --- a/frontend/src/components/Navbar.js +++ b/frontend/src/components/Navbar.js @@ -14,7 +14,6 @@ const Navbar = () => { setLoading(true) try { await login() - navigate('/') } catch (err) { setError('Failed to log in') console.log(err) diff --git a/frontend/src/contexts/CustomRoutes.js b/frontend/src/contexts/CustomRoutes.js index b4a4fc8..643f24f 100644 --- a/frontend/src/contexts/CustomRoutes.js +++ b/frontend/src/contexts/CustomRoutes.js @@ -1,12 +1,24 @@ import React from 'react' -import { Navigate, Outlet } from 'react-router-dom' +import { Navigate, Outlet, useLocation } from 'react-router-dom' import { useAuth } from './AuthContext' export const PrivateRoute = () => { const { currentUser } = useAuth() + const location = useLocation() + if (typeof currentUser === 'undefined') return

Loading.....

- if (!currentUser) return + if (!currentUser) + return ( + + ) return } @@ -16,6 +28,11 @@ export const PublicRoute = () => { export const LoggedInRedirect = () => { const { currentUser } = useAuth() - if (currentUser) return + + const location = useLocation() + + const prevLocation = location.state ? location.state['from'] : '/' + + if (currentUser) return return }