🐛 Fix routing

main
Vincent ASTOLFI 9 months ago
parent 056c90aeef
commit ed961b8f6e

@ -26,11 +26,11 @@ app.get('/', (req, res) => {
}) })
app.get('/scoreboard', (req, res) => { app.get('/scoreboard', (req, res) => {
return res.sendFile(path.normalize(path.join(__dirname, 'public/pages/scoreboardView.html'))) return res.sendFile(path.normalize(path.join(__dirname, '/public/pages/scoreboardView.html')))
}) })
app.get('/register', (req, res) => { app.get('/register', (req, res) => {
return res.sendFile(path.normalize(path.join(__dirname, '/public/pages/signupView.html'))) return res.sendFile(path.normalize(path.join(__dirname, '/public/pages/signupView.html')))
}) })
app.get('/game', (req, res) => { app.get('/game', (req, res) => {
@ -130,7 +130,7 @@ app.get('/user-info', (req, res) => {
} }
try { try {
const decoded = jwt.verify(token, secretKey); const decoded = jwt.verify(token, secretKey);
const query = 'SELECT pseudo FROM users WHERE pseudo = ?'; const query = 'SELECT pseudo FROM users WHERE pseudo = ?';
db.query(query, [decoded.pseudo], (err, results) => { db.query(query, [decoded.pseudo], (err, results) => {
if (err) { if (err) {
@ -143,6 +143,7 @@ app.get('/user-info', (req, res) => {
return res.json(results[0]); return res.json(results[0]);
}); });
} catch (ex) { } catch (ex) {
console.log(ex)
return res.status(400).send('Invalid token.'); return res.status(400).send('Invalid token.');
} }
}); });

@ -85,7 +85,7 @@
<p id="playerInfo"></p> <p id="playerInfo"></p>
<a href="/scorebaord"> <a href="/scoreboard">
see scorebaord see scorebaord
</a> </a>

@ -73,19 +73,10 @@ socket.on('opponent left', () => {
modal.style.display = 'block'; modal.style.display = 'block';
}) })
function deleteCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
socket.on("go to menu", () => { socket.on("go to menu", () => {
goToMenu() goToMenu()
}) })
socket.on("disconnect", () => {
deleteCookie('authToken');
window.location.href = "/"
});
// #region rematch handling // #region rematch handling
socket.on("ask for rematch", () => { socket.on("ask for rematch", () => {

@ -1,7 +1,3 @@
function deleteCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
const playerInfoDiv = document.getElementById('playerInfo'); const playerInfoDiv = document.getElementById('playerInfo');
@ -14,10 +10,8 @@ document.addEventListener('DOMContentLoaded', async () => {
}); });
if (response.status === 401) { if (response.status === 401) {
deleteCookie('authToken');
window.location.href = '/'; window.location.href = '/';
} else if (!response.ok) { } else if (!response.ok) {
deleteCookie('authToken');
playerInfoDiv.textContent = 'Error: Could not retrieve user information.'; playerInfoDiv.textContent = 'Error: Could not retrieve user information.';
window.location.href = '/'; window.location.href = '/';
} else { } else {

Loading…
Cancel
Save