rename isAuthenticated middleware to requireAuthenticated

pull/4/head
Cameron Clough 2022-03-24 00:00:25 +00:00
parent 8de0b2f8dd
commit 91d094eede
No known key found for this signature in database
GPG Key ID: BFB3B74B026ED43F
8 changed files with 30 additions and 25 deletions

View File

@ -5,7 +5,7 @@ export const getAccount = async (req, res, next) => {
next();
};
export const isAuthenticated = async (req, res, next) => {
export const requireAuthenticated = async (req, res, next) => {
const account = await authenticationController.getAuthenticatedAccount(req);
if (!account) {
res.status(401).json({

View File

@ -2,13 +2,13 @@ import bodyParser from 'body-parser';
import express from 'express';
import authenticationController from '../../../controllers/authentication';
import { isAuthenticated } from '../../../middlewares/authentication';
import { requireAuthenticated } from '../../../middlewares/authentication';
import { createAccount, verifyEmailToken } from '../../../controllers/users';
// /api/auth
const router = express.Router();
router.get('/session', isAuthenticated, async (req, res) => {
router.get('/session', requireAuthenticated, async (req, res) => {
return res.status(200).json({
success: true,
data: {

View File

@ -2,7 +2,7 @@ import express from 'express';
import log4js from 'log4js';
import { getURL, getToken } from '../../../controllers/authentication/oauth/google';
import { isAuthenticated } from '../../../middlewares/authentication';
import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router();
const logger = log4js.getLogger();
@ -32,7 +32,7 @@ router.get('/authentication/oauth/:provider', async (req, res) => {
}
});
router.get('/authentication/oauth/pair/:provider', isAuthenticated, async (req, res) => {
router.get('/authentication/oauth/pair/:provider', requireAuthenticated, async (req, res) => {
res.status(200);
});

View File

@ -1,10 +1,10 @@
import express from 'express';
import { isAuthenticated } from '../../../middlewares/authentication';
import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router();
router.get('/authentication/twofactor/enrol', isAuthenticated, async () => {
router.get('/authentication/twofactor/enrol', requireAuthenticated, async () => {
// TODO: implementation
});

View File

@ -4,7 +4,7 @@ import dirTree from 'directory-tree';
import express from 'express';
import log4js from 'log4js';
import { isAuthenticated } from '../../middlewares/authentication';
import { requireAuthenticated } from '../../middlewares/authentication';
import deviceController from '../../controllers/devices';
import { MutateDevice } from '../../schema/routes/devices';
@ -13,7 +13,7 @@ const logger = log4js.getLogger();
// /api/devices
const router = express.Router();
router.get('/', isAuthenticated, async (req, res) => {
router.get('/', requireAuthenticated, async (req, res) => {
const { account: { id } } = req;
const devices = await deviceController.getDevices(id);
@ -35,14 +35,14 @@ router.get('/', isAuthenticated, async (req, res) => {
}
*/
router.put('/:dongleId', [isAuthenticated, bodyParser.json()], async (req, res) => {
router.put('/:dongleId', [requireAuthenticated, bodyParser.json()], async (req, res) => {
const { body } = req;
logger.info(MutateDevice.isValid(body));
// TODO: response?
return res.json({ success: true });
});
router.get('/:dongleId/drives/:driveIdentifier/segment', isAuthenticated, async (req, res) => {
router.get('/:dongleId/drives/:driveIdentifier/segment', requireAuthenticated, async (req, res) => {
const {
account: { id: accountId },
params: {
@ -67,7 +67,7 @@ router.get('/:dongleId/drives/:driveIdentifier/segment', isAuthenticated, async
return res.json({ success: true, msg: 'ok', data: directoryTree });
});
router.get('/:dongleId/drives', isAuthenticated, async (req, res) => {
router.get('/:dongleId/drives', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params;
const { deleted } = req.query;
const accountId = req.account.id;
@ -82,7 +82,7 @@ router.get('/:dongleId/drives', isAuthenticated, async (req, res) => {
return res.json({ success: true, data: drives });
});
router.get('/:dongleId/bootlogs', isAuthenticated, async (req, res) => {
router.get('/:dongleId/bootlogs', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params;
const accountId = req.account.id;
const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId);
@ -95,7 +95,7 @@ router.get('/:dongleId/bootlogs', isAuthenticated, async (req, res) => {
return res.json({ success: true, data: bootlogs });
});
router.get('/:dongleId/crashlogs', isAuthenticated, async (req, res) => {
router.get('/:dongleId/crashlogs', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params;
const accountId = req.account.id;
const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId);

View File

@ -3,7 +3,7 @@ import express from 'express';
import { AthenaReturnedData } from '../../../models';
import authenticationController from '../../controllers/authentication';
import deviceController from '../../controllers/devices';
import { isAuthenticated } from '../../middlewares/authentication';
import { requireAuthenticated } from '../../middlewares/authentication';
// /api/realtime
const router = express.Router();
@ -28,7 +28,7 @@ const whitelistParams = {
// TODO: use middleware to get device from dongle id
router.get('/:dongleId/connected', isAuthenticated, async (req, res) => {
router.get('/:dongleId/connected', requireAuthenticated, async (req, res) => {
const { account, params: { dongleId } } = req;
const device = await deviceController.getDeviceFromDongleId(dongleId);
@ -61,7 +61,7 @@ router.get('/:dongleId/connected', isAuthenticated, async (req, res) => {
});
// TODO: change to POST request
router.get('/:dongleId/send/:method/', isAuthenticated, async (req, res) => {
router.get('/:dongleId/send/:method/', requireAuthenticated, async (req, res) => {
const { account, params: { dongleId, method } } = req;
if (!whitelistParams[method.toLowerCase()]) {

View File

@ -4,7 +4,7 @@ import cookieParser from 'cookie-parser';
import controllers from '../../controllers';
import deviceController from '../../controllers/devices';
import { isAuthenticated } from '../../middlewares/authentication';
import { requireAuthenticated } from '../../middlewares/authentication';
// TODO Remove this, pending on removing all auth logic from routes
@ -59,7 +59,7 @@ router.get('/', runAsyncWrapper(async (req, res) => {
});
}));
router.get('/overview', isAuthenticated, runAsyncWrapper(async (req, res) => {
router.get('/overview', requireAuthenticated, runAsyncWrapper(async (req, res) => {
const { account } = req;
const devices = await deviceController.getDevices(account.id);
@ -74,7 +74,7 @@ router.get('/overview', isAuthenticated, runAsyncWrapper(async (req, res) => {
});
}));
router.get('/unpair_device/:dongleId', isAuthenticated, runAsyncWrapper(async (req, res) => {
router.get('/unpair_device/:dongleId', requireAuthenticated, runAsyncWrapper(async (req, res) => {
const { account, params: { dongleId } } = req;
const device = await deviceController.getDeviceFromDongleId(dongleId);
@ -92,15 +92,20 @@ router.get('/unpair_device/:dongleId', isAuthenticated, runAsyncWrapper(async (r
return res.status(200).json({ success: true });
}));
router.post('/pair_device', [isAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
const { account, body: { qrString } } = req;
router.post('/pair_device', [requireAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
const { qrString } = req.body;
if (!qrString) {
return res.json({ success: false, msg: 'BAD_REQUEST', status: 400 });
}
const { account } = req;
const pairDevice = await controllers.devices.pairDevice(account, qrString);
if (!pairDevice.success) {
return res.json({ success: false, msg: 'error', data: pairDevice });
return res.json({
success: false,
msg: 'error',
data: pairDevice,
});
}
return res.json({
@ -111,7 +116,7 @@ router.post('/pair_device', [isAuthenticated, bodyParser.urlencoded({ extended:
});
}));
router.post('/password/change', [isAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
router.post('/password/change', [requireAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
const { account, body: { oldPassword, newPassword } } = req;
const result = await controllers.authentication.changePassword(
account,

View File

@ -12,7 +12,7 @@ import helperController from '../controllers/helpers';
import mailingController from '../controllers/mailing';
import deviceController from '../controllers/devices';
import userController from '../controllers/users';
import { getAccount, isAuthenticated } from '../middlewares/authentication';
import { getAccount, requireAuthenticated } from '../middlewares/authentication';
const logger = log4js.getLogger();
let models;