Store token in localStorage

This commit is contained in:
Ceda EI 2019-03-29 11:08:03 +05:30
parent 6c5dc60dac
commit 695927b9e8
1 changed files with 11 additions and 2 deletions

View File

@ -3,12 +3,21 @@ import PropTypes from "prop-types";
export default (player) => {
function Login(props) {
const [input, setInput] = useState("");
const [input, setInput] = useState(localStorage.getItem("token"));
return (
<div className="login">
<input type="text" placeholder="Token ID" value={input}
onChange={evt => setInput(evt.target.value)} />
<button onClick={() => player.auth(input).then(x => props.setLoggedIn(x))}>Submit</button>
<button
onClick={
() => player.auth(input)
.then(x => {
props.setLoggedIn(x);
if (x === true) {
localStorage.setItem("token", input);
}
})
}>Submit</button>
</div>
);
}