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
This commit is contained in:
Maieul BOYER 2025-10-02 01:42:09 +02:00 committed by Maix0
parent bca385adc9
commit 812959b16f
3 changed files with 8 additions and 4 deletions

View file

@ -42,11 +42,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
if (!isNullish(user.otp)) { if (!isNullish(user.otp)) {
// yes -> we ask them to fill it, // yes -> we ask them to fill it,
// send them somehting to verify that they indeed passed throught the user+password phase // 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... // 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 { catch {
return makeResponse('failed', 'login.failed.generic'); return makeResponse('failed', 'login.failed.generic');

View file

@ -47,11 +47,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
// password is good too ! // password is good too !
if (this.db.getUserFromName(name) !== undefined) {return makeResponse('failed', 'signin.failed.username.existing');} 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');} 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... // 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 }); return makeResponse('success', 'signin.success', { token: userToken });
}, },
); );

View file

@ -19,6 +19,10 @@ const start = async () => {
}; };
const f: FastifyInstance = fastify({ logger: envToLogger.development }); const f: FastifyInstance = fastify({ logger: envToLogger.development });
process.on('SIGTERM', () => {
f.log.info('Requested to shutdown');
process.exit(134);
});
try { try {
await f.register(app, {}); await f.register(app, {});
await f.listen({ port: 80, host: '0.0.0.0' }); await f.listen({ port: 80, host: '0.0.0.0' });