Is there anything I can do to prevent users to run js function which is in file from console ? I have this getReward function here:
function getReward(){
$('.reward-button').remove();
$('#rewardBtn').remove();
document.getElementById("fightInfo").innerHTML =
'<strong>You</strong> won the fight.<br><strong>Reward:</strong><br>Gold: ' +gold+' <img src="/img/gold.png" style="margin-top: -1%"><br>EXP: '+exp+'<br>'
+
'<br>'
+
'<button style="font-size: 24px;" class="btn btn-danger" onclick="backToArena();">⚔️<br>Back To Arena</button>';
socket.emit('win-fight', {
gold: gold,
exp: exp,
username: userName,
enemyname: enemyName
});
}
function backToArena(){
window.location.href = "/arena";
}
The problem is that user can just type in console getReward(); and he automatically get's the reward because then socket works and it goes to server side from client side. Is there anyway to prevent this ?
UPDATE
document.getElementById("rewardBtn").innerHTML =
'<button style="background-color: blue; font-size: 24px;" class="btn btn-primary" id="reward-button">Get reward 🏆</button>';
And then I do this:
document.querySelector('#reward-button').addEventListener('click', getReward);
But this doesn't run getReward function nothing happens no error.