Add logout

This commit is contained in:
Ceda EI 2019-03-29 11:44:42 +05:30
parent 695927b9e8
commit 13e2851e4c
3 changed files with 23 additions and 7 deletions

View File

@ -3,7 +3,7 @@ import PropTypes from "prop-types";
export default (player) => {
function Login(props) {
const [input, setInput] = useState(localStorage.getItem("token"));
const [input, setInput] = useState(localStorage.getItem("token") ? localStorage.getItem("token"): "" );
return (
<div className="login">
<input type="text" placeholder="Token ID" value={input}

View File

@ -1,7 +1,23 @@
import React from "react";
export default () => function MainApp() {
return (
<div className="main">
</div>
);
import PropTypes from "prop-types";
export default () => {
function MainApp(props) {
return (
<div className="main">
<header>
<p>Questable</p>
<button
onClick={() => {
props.setLoggedIn(false);
localStorage.removeItem("token");
}}>Logout</button>
</header>
</div>
);
}
MainApp.propTypes = {
setLoggedIn: PropTypes.func,
};
return MainApp;
};

View File

@ -14,7 +14,7 @@ const MainApp = mainapp();
function App(){
const [loggedIn, setLoggedIn] = useState(false);
return loggedIn ? <MainApp /> : <Login setLoggedIn={setLoggedIn} />;
return loggedIn ? <MainApp setLoggedIn={setLoggedIn} /> : <Login setLoggedIn={setLoggedIn} />;
}
ReactDOM.render(<App />, document.getElementById("root"));