This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<BrowserRouter basename={'/'}> | |
<Routes> | |
<Route path='/auth' element={<Auth />}> | |
<Route path='login' element={<Login />} /> | |
</Route> | |
<Route path="/" element={<App />}> | |
<Route path='' element={ | |
<ProtectedRoute> | |
<Home /> | |
</ProtectedRoute> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserRouter, Route, Routes } from 'react-router-dom'; | |
import Login from './auth/login/Login'; | |
import Auth from './auth/Auth'; | |
import App from './App'; | |
import ProtectedRoute from './util/ProtectedRoute'; | |
import Home from './portal/home/Home'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import { Outlet } from "react-router-dom"; | |
import PortalFooter from "./portal/footer/PortalFooter"; | |
import PortalNavbar from "./portal/navbar/PortalNavbar"; | |
function App() { | |
const [isLoggedIn, setIsLoggedIn] = useState(false); | |
const checkUserToken = () => { | |
const userToken = localStorage.getItem('user-token'); | |
if (!userToken || userToken === 'undefined') { | |
setIsLoggedIn(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import { Outlet } from "react-router-dom"; | |
import PortalFooter from "./portal/footer/PortalFooter"; | |
import PortalNavbar from "./portal/navbar/PortalNavbar"; | |
function App() { | |
const [isLoggedIn, setIsLoggedIn] = useState(false); | |
const checkUserToken = () => { | |
const userToken = localStorage.getItem('user-token'); | |
if (!userToken || userToken === 'undefined') { | |
setIsLoggedIn(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Container } from 'react-bootstrap'; | |
const Home = () => { | |
return ( | |
<React.Fragment> | |
<Container className='py-5'> | |
<h3 className='fw-normal'>Welcome Home.</h3> | |
</Container> | |
</React.Fragment> | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import { Route, useNavigate } from "react-router-dom"; | |
const ProtectedRoute = (props) => { | |
const navigate = useNavigate(); | |
const [isLoggedIn, setIsLoggedIn] = useState(false); | |
const checkUserToken = () => { | |
const userToken = localStorage.getItem('user-token'); | |
if (!userToken || userToken === 'undefined') { | |
setIsLoggedIn(false); | |
return navigate('/auth/login'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loginAPI = 'https://tararoutray.com/demo/react-auth/login.php'; | |
const navigate = useNavigate(); | |
const submitLoginForm = (event) => { | |
event.preventDefault(); | |
const formElement = document.querySelector('#loginForm'); | |
const formData = new FormData(formElement); | |
const formDataJSON = Object.fromEntries(formData); | |
const btnPointer = document.querySelector('#login-btn'); | |
btnPointer.innerHTML = 'Please wait..'; | |
btnPointer.setAttribute('disabled', true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Outlet } from "react-router-dom"; | |
import AuthFooter from "./footer/AuthFooter"; | |
import AuthNavbar from "./navbar/AuthNavbar"; | |
const Auth = () => { | |
return ( | |
<React.Fragment> | |
<AuthNavbar /> | |
<Outlet /> | |
<AuthFooter /> |