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:
parent
bca385adc9
commit
812959b16f
3 changed files with 8 additions and 4 deletions
|
|
@ -42,11 +42,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
|||
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');
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
|||
// 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 });
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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' });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue