diff --git a/src/views/JoinView.vue b/src/views/JoinView.vue index 1305d8c..9b44350 100644 --- a/src/views/JoinView.vue +++ b/src/views/JoinView.vue @@ -12,26 +12,31 @@ const player = usePlayerStore() const game = useGameStore() const bot = useBotStore() -if (game.owner == player.id || game.opponent.id == player.id) { - window.location.href = window.location.origin + '/lobby/' + game.id - return -} - -game.$reset() -bot.$reset() -localStorage.removeItem('game') -localStorage.removeItem('bot') - -const websocket = useWebsocketStore() -if (player.id == null) player.initPlayer() -websocket.init(route.params.gameId) - const join = () => { res = websocket.send({ action: 'join', from: player.id }) } + +onBeforeMount(() => { + console.log(game.owner, game.opponent.id, player.id) + if (game.owner == player.id || game.opponent.id == player.id) { + window.location.href = window.location.origin + '/lobby/' + game.id + return + } +}) + +onMounted(() => { + game.$reset() + bot.$reset() + localStorage.removeItem('game') + localStorage.removeItem('bot') + + const websocket = useWebsocketStore() + if (player.id == null) player.initPlayer() + websocket.init(route.params.gameId) +})