From e15cb8e776b7d51b89d6166446717087ce884615 Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 23 Oct 2025 16:00:24 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(auth):=20r?= =?UTF-8?q?emove=20working=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user/dUser.js | 12 ++++++------ src/api/user/gUser.js | 1 + src/utils/authDB.js | 2 +- src/utils/authUserRemove.js | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/user/dUser.js b/src/api/user/dUser.js index 864d8cb..fad5571 100644 --- a/src/api/user/dUser.js +++ b/src/api/user/dUser.js @@ -1,16 +1,16 @@ export async function dUser(request, reply, fastify, getUserInfo, deleteMatchHistory, deleteFriends, deleteUser) { try { - const userId = request.params.userId; - if (request.user !== userId && request.user !== 'admin') { + if (request.user !== 'admin') { return reply.code(401).send({ error: 'Unauthorized' }); } + const userId = request.params.userId; if (!getUserInfo.get(userId)) { return reply.code(404).send({ error: "User does not exist" }); } - deleteMatchHistory.run('pong', request.params.userId); - deleteMatchHistory.run('tetris', request.params.userId); - deleteFriends.run(request.params.userId); - deleteUser.run(request.params.userId); + deleteMatchHistory.run('pong', userId); + deleteMatchHistory.run('tetris', userId); + deleteFriends.run(userId); + deleteUser.run(userId); return reply.code(200).send({ msg: "User deleted successfully" }); } catch (err) { fastify.log.error(err); diff --git a/src/api/user/gUser.js b/src/api/user/gUser.js index 24648bd..6750f75 100644 --- a/src/api/user/gUser.js +++ b/src/api/user/gUser.js @@ -7,6 +7,7 @@ export async function gUser(request, reply, fastify, getUserInfo) { if (!getUserInfo.get(userId)) { return reply.code(404).send({ error: "User does not exist" }); } + const userInfo = getUserInfo.get(userId); return reply.code(200).send({ username: userInfo.username, displayName: userInfo.displayName, diff --git a/src/utils/authDB.js b/src/utils/authDB.js index 69d1bde..a4611f3 100644 --- a/src/utils/authDB.js +++ b/src/utils/authDB.js @@ -83,7 +83,7 @@ function getUser(user) { } function rmUser(user) { - const stmt = database.prepare('DELETE * FROM credentials WHERE username = ?'); + const stmt = database.prepare('DELETE FROM credentials WHERE username = ?'); stmt.run(user); } diff --git a/src/utils/authUserRemove.js b/src/utils/authUserRemove.js index 8af7503..2fc3bfc 100644 --- a/src/utils/authUserRemove.js +++ b/src/utils/authUserRemove.js @@ -8,7 +8,7 @@ export async function authUserRemove(username, fastify) { const url = (process.env.USER_URL || "http://localhost:3002") + "/users/" + username; const cookie = fastify.jwt.sign({ user: "admin" }); - await axios.post( + await axios.delete( url, { headers: {