battleship-front/src/screens/Connect.js
Administrator 82e06917cf title
2022-08-29 11:09:09 +03:00

37 lines
942 B
JavaScript

import {Component} from 'react';
import request from '../scripts/requests';
class Connect extends Component {
constructor(props) {
super(props);
this.queryParams = new URLSearchParams(window.location.search);
const game_id = this.queryParams.get('gameId');
localStorage.setItem('gameId', game_id);
}
getToken() {
return this.queryParams.get('token');
}
getGameId() {
return localStorage.getItem('gameId');
}
componentDidMount() {
document.title = "Подключиться к игре";
request("attend_game", {
game_id: this.getGameId(),
attend_token: this.getToken()
}, (response) => {
localStorage.setItem("token", response.token);
window.location.href = "/new_game?gameId=" + this.getGameId()
})
}
render() {
return <div></div>
}
}
export default Connect;