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
| function Header(props) { | |
| ... | |
| function renderLogout() { | |
| if(props.location.pathname === '/home'){ | |
| return( | |
| <div className="ml-auto"> | |
| <button className="btn btn-danger" onClick={() => handleLogout()}>Logout</button> | |
| </div> | |
| ) | |
| } |
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 jwt = require("jsonwebtoken"); | |
| const User = require('../models/User'); | |
| module.exports = async function(req, res, next) { | |
| const token = req.header("token"); | |
| if (!token) return res.status(401).json({ message: "Auth Error" }); | |
| try { | |
| const decoded = jwt.verify(token, "randomString"); | |
| req.user = decoded.user; | |
| const user = await User.findById(decoded.user.id); |
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
| function Home(props) { | |
| useEffect(() => { | |
| axios.get(API_BASE_URL+'/user/me', { headers: { 'token': localStorage.getItem(ACCESS_TOKEN_NAME) }}) | |
| .then(function (response) { | |
| if(response.status !== 200){ | |
| redirectToLogin() | |
| } | |
| }) | |
| .catch(function (error) { | |
| redirectToLogin() |
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 PrivateRoute from './utils/PrivateRoute'; | |
| ... | |
| <Switch> | |
| ..... | |
| <PrivateRoute path="/home"> | |
| <Home/> | |
| </PrivateRoute> | |
| </Switch> |
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 { Redirect, Route } from "react-router-dom"; | |
| import { ACCESS_TOKEN_NAME } from '../constants/apiContants'; | |
| function PrivateRoute({ children, ...rest }) { | |
| return ( | |
| <Route | |
| {...rest} | |
| render={({ location }) => | |
| localStorage.getItem(ACCESS_TOKEN_NAME) ? ( | |
| children |
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
| if(response.status === 200){ | |
| setState(prevState => ({ | |
| ...prevState, | |
| 'successMessage' : 'Registration successful. Redirecting to home page..' | |
| })) | |
| localStorage.setItem(ACCESS_TOKEN_NAME,response.data.token); | |
| redirectToHome(); | |
| props.showError(null) | |
| } |
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} from 'react'; | |
| import axios from 'axios'; | |
| function App() { | |
| ... | |
| const handleInputSubmission = () => { | |
| if(selectedObject && Object.keys(selectedObject).length === 7) { | |
| ... | |
| axios.post(process.env.REACT_APP_HEROKU_SERVER_URL, selectedObject) | |
| .then(function (response) { | |
| setPredictionLoading(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,{ useState } from 'react'; | |
| ... | |
| function OptionSelection({itemKey, setOptionInObject}) { | |
| const [currentSelectedOption, setSelectedOption] = useState(null); | |
| const handleDropDownSelection = (consoleOption) => { | |
| setSelectedOption(consoleOption) | |
| setOptionInObject(itemKey, consoleOption) | |
| } | |
| ... | |
| } |
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 optionSources from '../optionsSources.json'; | |
| function OptionSelection({itemKey, setOptionInObject}) { | |
| ... | |
| const renderOptionsDropdown = () => { | |
| const selectionOptions = optionSources[itemKey].options; | |
| return selectionOptions.map((selectionOption, index)=>{ | |
| return ( | |
| <div className="dropdown-item pointer" | |
| key={`${index}${selectionOption}`} | |
| onClick={() => handleDropDownSelection(selectionOption)} |
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 } from 'react'; | |
| import optionSources from '../optionsSources.json'; | |
| function OptionSelection({itemKey, setOptionInObject}) { | |
| const title = optionSources[itemKey].dropDownPlaceholder; | |
| const icon = optionSources[itemKey].icon; | |
| return( | |
| <div className="d-flex justify-content-start align-items-center mt-2 selection-item"> | |
| <div className="option-label"> | |
| <b><span role="img" aria-label="label-icon">{icon}</span>{` ${title}`}</b> | |
| </div> |