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, {useContext} from 'react' | |
| import {AuthContext} from '../contexts/AuthContextProvider'; | |
| import { Navigate, useLocation } from 'react-router-dom'; | |
| const PrivatePath = ({children}) => { | |
| //Used to store the current location, so that it can be redirected back to this component after login | |
| const location = useLocation() | |
| //Reads the context value | |
| const authContext = useContext(AuthContext); |
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, {useContext, useState} from 'react'; | |
| import { AuthContext } from '../contexts/AuthContextProvider'; | |
| import { useNavigate, useLocation } from "react-router-dom"; | |
| import Button from '@mui/material/Button' | |
| import Paper from '@mui/material/Paper'; | |
| import TextField from '@mui/material/TextField'; | |
| const Login = () => { | |
| const navigate = useNavigate(); |
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, Routes, Route} from 'react-router-dom'; | |
| import AuthContext from './contexts/AuthContextProvider.js' | |
| import PrivatePath from './components/PrivatePath.js'; | |
| import Login from './components/Login.js'; | |
| import Navigation from './components/Navigation.js'; | |
| import PrivateComponent from './components/PrivateComponent.js'; | |
| import PublicComponent from './components/PublicComponent.js'; | |
| import LandingPage from './components/LandingPage.js'; | |
| function App() { |
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,{useState, createContext} from 'react'; | |
| //Creating a context using 'createContext' | |
| export const AuthContext = createContext(null); | |
| const AuthContextProvider = ({children}) =>{ | |
| //Boolean value that would simply indicate whether User is signed in or nor | |
| const [authState, setAuthState] = useState(false); | |
| //Object to store other user details like name, email, etc |