X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fauth.ts;h=c5424be979b1703b7ba479a63c9925fa424c7871;hb=a9bfa85d2cdf13670aaced740da5b493fbeddfce;hp=f38373624c1cccf006c3be35de067cdf7c552516;hpb=4024c44f9027a32809931de0692d40d001df721c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/auth.ts b/server/middlewares/auth.ts index f38373624..c5424be97 100644 --- a/server/middlewares/auth.ts +++ b/server/middlewares/auth.ts @@ -1,7 +1,7 @@ -import * as express from 'express' +import express from 'express' import { Socket } from 'socket.io' import { getAccessToken } from '@server/lib/auth/oauth-model' -import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { logger } from '../helpers/logger' import { handleOAuthAuthenticate } from '../lib/auth/oauth' @@ -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) })