File size: 1,806 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { useContext } from "react";
import "./styles.css";

import LandingSection from "containers/LandingSection/LandingSection";
import Login from "containers/Login/Login";
import Browse from 'containers/Browse/Browse'
import { Switch, Route, Redirect } from "react-router-dom";
import { AuthenticationContext } from 'context/Authentication'
import NotFoundPage from 'components/StaticPages/NotFoundPage/NotFoundPage'

export default function App() {
  const authContext = useContext(AuthenticationContext)

  const checkAuthAndSetBrowseComponent = (propsObject) => {
    return (authContext.authenticated || localStorage.getItem('profileSelected')) ?
      <Browse {...propsObject} /> :
      <Redirect to="/login" />
  }

  return (
    <div className="App">
      <Switch>
        <Route exact path="/browse" render={() => checkAuthAndSetBrowseComponent({ route: '/browse' })}>
        </Route>
        <Route exact path="/browse/tv" render={() => checkAuthAndSetBrowseComponent({ route: '/browse/tv' })}>
        </Route>
        <Route exact path="/browse/movies" render={() => checkAuthAndSetBrowseComponent({ route: '/browse/movies' })}>
        </Route>
        <Route exact path="/browse/latest" render={() => checkAuthAndSetBrowseComponent({ route: '/browse/latest' })}>
        </Route>
        <Route exact path="/browse/list" render={() => checkAuthAndSetBrowseComponent({ route: '/browse/list' })}>
        </Route>
        <Route exact path="/search" render={() => checkAuthAndSetBrowseComponent({ route: '/search' })}>
        </Route>
        <Route exact path="/login" component={Login}>
        </Route>
        <Route exact path="/" component={LandingSection}>
        </Route>
        <Route exact component={NotFoundPage}>
        </Route>
      </Switch>
    </div >
  );
}