Created
July 5, 2019 07:41
-
-
Save daniilgri/bca098798649cde6a9c01243fb9b7a42 to your computer and use it in GitHub Desktop.
This file contains 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 Cookies from "js-cookie"; | |
import { Route, Switch } from "react-router"; | |
import { Redirect } from "react-router-dom"; | |
import MessagesPage from "./components/MessagesPage"; | |
import LoginPageContainer from "./containers/loginPageContainer"; | |
import RegisterPageContainer from "./containers/registerPageContainer"; | |
function isLogged() { | |
const cookie = Cookies.get("connect.sid"); | |
if (!cookie) { | |
return 0; | |
} | |
return 1; | |
} | |
const routes = ( | |
<Switch> | |
<Route | |
path="/messages" | |
render={() => (isLogged() ? <MessagesPage /> : <Redirect to="/login" />)} | |
/> | |
<Route | |
path="/login" | |
render={() => | |
isLogged() ? <Redirect to="/messages" /> : <LoginPageContainer /> | |
} | |
/> | |
<Route | |
path="/register" | |
render={() => | |
isLogged() ? <Redirect to="/messages" /> : <RegisterPageContainer /> | |
} | |
/> | |
</Switch> | |
); | |
export default routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment