From ae4838166be24eedee63dac2c645b110d05566fc Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 1 Oct 2025 19:44:48 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat(auth-api?= =?UTF-8?q?):=20/logout=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/default.js | 3 +++ src/api/auth/logout.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/api/auth/logout.js diff --git a/src/api/auth/default.js b/src/api/auth/default.js index 6a15651..78e7411 100644 --- a/src/api/auth/default.js +++ b/src/api/auth/default.js @@ -10,6 +10,7 @@ import { gRegisterCallback } from './gRegisterCallback.js'; import { totpSetup } from './totpSetup.js'; import { totpDelete } from './totpDelete.js'; import { totpVerify } from './totpVerify.js'; +import { logout } from './logout.js'; const saltRounds = 10; export const appName = process.env.APP_NAME || 'knl_meowscendence'; @@ -107,4 +108,6 @@ export default async function(fastify, options) { } } }, async (request, reply) => { return register(request, reply, saltRounds, fastify); }); + + fastify.get('/logout', {}, async (request, reply) => { return logout(request, reply, fastify); }) } diff --git a/src/api/auth/logout.js b/src/api/auth/logout.js new file mode 100644 index 0000000..d4117b8 --- /dev/null +++ b/src/api/auth/logout.js @@ -0,0 +1,17 @@ +/** + * @async + * @param {import("fastify").FastifyReply} reply + * + * @returns {import("fastify").FastifyReply} + */ +export async function logout(reply) { + try { + return reply + .code(200) + .clearCookie() + .send({ msg: "Logout successful" }); + } catch { + fastify.log.error(err); + return reply.code(500).send({ error: "Internal server error" }); + } +} From e23922d4e3441ccb7b74df9d53a483e3c0a613e5 Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 1 Oct 2025 19:50:03 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=E3=80=8C=F0=9F=93=9D=E3=80=8D=20doc(auth-a?= =?UTF-8?q?pi):=20logout=20doc=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/auth/logout.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 doc/auth/logout.md diff --git a/doc/auth/logout.md b/doc/auth/logout.md new file mode 100644 index 0000000..98b6edc --- /dev/null +++ b/doc/auth/logout.md @@ -0,0 +1,24 @@ +# Logout + +Available endpoints: +- GET `/logout` + +Common return: +- 500 with response +```json +{ + "error": "Internal server error" +} +``` + +## GET `/logout` + +Used to logout the client (it just delete the cookie) + +Returns: +- 200 with response and clear cookie +```json +{ + "msg": "Logout successful" +} +``` From 544289e2af9f88ae64282ee85f1fc91d3482edc8 Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 1 Oct 2025 20:11:27 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fix?= =?UTF-8?q?ed=20a=20massive=20skill=20issue=20but=20f*ck=20js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/default.js | 2 +- src/api/auth/logout.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/auth/default.js b/src/api/auth/default.js index 78e7411..0e491ac 100644 --- a/src/api/auth/default.js +++ b/src/api/auth/default.js @@ -109,5 +109,5 @@ export default async function(fastify, options) { } }, async (request, reply) => { return register(request, reply, saltRounds, fastify); }); - fastify.get('/logout', {}, async (request, reply) => { return logout(request, reply, fastify); }) + fastify.get('/logout', {}, async (request, reply) => { return logout(reply, fastify); }) } diff --git a/src/api/auth/logout.js b/src/api/auth/logout.js index d4117b8..84d1d22 100644 --- a/src/api/auth/logout.js +++ b/src/api/auth/logout.js @@ -1,10 +1,11 @@ /** * @async * @param {import("fastify").FastifyReply} reply + * @param {import("fastify").FastifyInstance} fastify * * @returns {import("fastify").FastifyReply} */ -export async function logout(reply) { +export async function logout(reply, fastify) { try { return reply .code(200) From 705571ee120e2f86ade38b2c8768211867aa555c Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 1 Oct 2025 20:16:58 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fix?= =?UTF-8?q?ed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/logout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/auth/logout.js b/src/api/auth/logout.js index 84d1d22..b3c57ef 100644 --- a/src/api/auth/logout.js +++ b/src/api/auth/logout.js @@ -9,7 +9,7 @@ export async function logout(reply, fastify) { try { return reply .code(200) - .clearCookie() + .clearCookie("token") .send({ msg: "Logout successful" }); } catch { fastify.log.error(err);