feat: major code refactor, add login and register endpoints with swagger
All checks were successful
Update changelog / changelog (push) Successful in 27s

This commit is contained in:
2025-12-29 18:26:50 +01:00
parent 3f225a1ecb
commit 41f3b0f0f2
22 changed files with 1425 additions and 128 deletions

View File

@@ -0,0 +1,50 @@
// Heavily based on:
// https://github.com/TomDoesTech/REST-API-Tutorial-Updated/blob/7b5f040e1acd94d267df585516b33ee7e3b75f70/src/middleware/deserializeUser.ts
import { get } from 'lodash';
import { Request, Response, NextFunction } from 'express';
import { verifyJwt } from '../tools/jwt';
const inferUser = async (
req: Request,
res: Response,
next: NextFunction
) => {
const accessToken = get(req, 'headers.authorization', '').replace(
/^Bearer\s/,
''
);
if (!accessToken) return next();
const { decoded } = verifyJwt(accessToken, 'accessTokenPublicKey');
// console.log('decoded user:', decoded);
if (decoded) {
res.locals.user = decoded;
return next();
}
/*
// refresh token handling is not (yet) implemented
const refreshToken = get(req, 'headers.x-refresh');
if (expired && refreshToken) {
const newAccessToken = await reIssueAccessToken({ refreshToken });
if (newAccessToken) {
res.setHeader('x-access-token', newAccessToken);
}
const result = verifyJwt(newAccessToken as string, 'accessTokenPublicKey');
res.locals.user = result.decoded;
return next();
}
*/
return next();
};
export default inferUser;