Store token in localStorage
This commit is contained in:
parent
6c5dc60dac
commit
695927b9e8
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue