-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'
.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
+ })
})
}
// 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)
})