From 812959b16f8bdea7429adfe317986833d78802f4 Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Thu, 2 Oct 2025 01:42:09 +0200 Subject: [PATCH] feat(auth): fixed JWT using wrong data and SIGTERM handler - JWT now uses the correct information to determine the user (id instead of name) - A SIGTERM handler has been made, such that docker doesn't use SIGKILL --- src/auth/src/routes/login.ts | 4 ++-- src/auth/src/routes/signin.ts | 4 ++-- src/auth/src/run.ts | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/auth/src/routes/login.ts b/src/auth/src/routes/login.ts index 10121a9..478ea73 100644 --- a/src/auth/src/routes/login.ts +++ b/src/auth/src/routes/login.ts @@ -42,11 +42,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise => { if (!isNullish(user.otp)) { // yes -> we ask them to fill it, // send them somehting to verify that they indeed passed throught the user+password phase - return makeResponse('otpRequired', 'login.otpRequired', { token: this.signJwt('otp', user.name) }); + return makeResponse('otpRequired', 'login.otpRequired', { token: this.signJwt('otp', user.id) }); } // every check has been passed, they are now logged in, using this token to say who they are... - return makeResponse('success', 'login.success', { token: this.signJwt('auth', user.name) }); + return makeResponse('success', 'login.success', { token: this.signJwt('auth', user.id) }); } catch { return makeResponse('failed', 'login.failed.generic'); diff --git a/src/auth/src/routes/signin.ts b/src/auth/src/routes/signin.ts index b22ade6..ff68191 100644 --- a/src/auth/src/routes/signin.ts +++ b/src/auth/src/routes/signin.ts @@ -47,11 +47,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise => { // password is good too ! if (this.db.getUserFromName(name) !== undefined) {return makeResponse('failed', 'signin.failed.username.existing');} - const u = await this.db.createUser(name, password); + const u = await this.db.createUser(name, password, false); if (isNullish(u)) {return makeResponse('failed', 'signin.failed.generic');} // every check has been passed, they are now logged in, using this token to say who they are... - const userToken = this.signJwt('auth', u.name); + const userToken = this.signJwt('auth', u.id); return makeResponse('success', 'signin.success', { token: userToken }); }, ); diff --git a/src/auth/src/run.ts b/src/auth/src/run.ts index 9f9e3dd..d3d410f 100644 --- a/src/auth/src/run.ts +++ b/src/auth/src/run.ts @@ -19,6 +19,10 @@ const start = async () => { }; const f: FastifyInstance = fastify({ logger: envToLogger.development }); + process.on('SIGTERM', () => { + f.log.info('Requested to shutdown'); + process.exit(134); + }); try { await f.register(app, {}); await f.listen({ port: 80, host: '0.0.0.0' });