jwt gen & rename fixes

This commit is contained in:
Julian Krauser 2025-01-22 11:57:19 +01:00
parent 313785b4ac
commit a165231c47
13 changed files with 101 additions and 41 deletions

View file

@ -10,6 +10,7 @@ import UnauthorizedRequestException from "../exceptions/unauthorizedRequestExcep
import RefreshService from "../service/refreshService";
import WebapiService from "../service/user/webapiService";
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
import WebapiCommandHandler from "../command/user/webapi/webapiCommandHandler";
/**
* @description Check authentication status by token
@ -20,13 +21,15 @@ import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
export async function getWebApiAccess(req: Request, res: Response): Promise<any> {
const bearer = req.headers.authorization?.split(" ")?.[1] ?? undefined;
let { expiry } = await WebapiService.getByToken(bearer);
let { id, expiry } = await WebapiService.getByToken(bearer);
if (new Date() > new Date(expiry)) {
if (expiry != null && new Date() > new Date(expiry)) {
throw new ForbiddenRequestException("api token expired");
}
let accessToken = await JWTHelper.buildWebapiToken(bearer);
await WebapiCommandHandler.updateUsage({ id });
let accessToken = await JWTHelper.buildWebapiToken(bearer, expiry);
res.json({
accessToken,