X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fauth.ts;h=176461cc2cae41fb09aff44472adbb23080c2db7;hb=6018a464e6733dd71c8fbdf25f260e43e931309c;hp=f38373624c1cccf006c3be35de067cdf7c552516;hpb=903353d67a8d0fdda8465ed6c57b77a9a5afbe92;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/auth.ts b/server/middlewares/auth.ts index f38373624..176461cc2 100644 --- a/server/middlewares/auth.ts +++ b/server/middlewares/auth.ts @@ -16,11 +16,11 @@ function authenticate (req: express.Request, res: express.Response, next: expres .catch(err => { logger.warn('Cannot authenticate.', { err }) - return res.status(err.status) - .json({ - error: 'Token is invalid.', - code: err.name - }) + return res.fail({ + status: err.status, + message: 'Token is invalid', + type: err.name + }) }) } @@ -52,7 +52,12 @@ function authenticatePromiseIfNeeded (req: express.Request, res: express.Respons // Already authenticated? (or tried to) if (res.locals.oauth?.token.User) return resolve() - if (res.locals.authenticated === false) return res.sendStatus(HttpStatusCode.UNAUTHORIZED_401) + if (res.locals.authenticated === false) { + return res.fail({ + status: HttpStatusCode.UNAUTHORIZED_401, + message: 'Not authenticated' + }) + } authenticate(req, res, () => resolve(), authenticateInQuery) })