From 7d6aa26ab67d40cfb5d267308a808a541dd49cde Mon Sep 17 00:00:00 2001 From: Philip Bruland Date: Thu, 18 Jul 2019 15:26:14 +0100 Subject: [PATCH] Issue #7: Lay out and explain file structure - Move auth code to middleware folder - The auth code runs as middleware --- Components/User/index.js | 2 +- {Utils => Middleware}/Passport/auth.js | 1 + {Utils => Middleware}/Passport/config.js | 0 index.js | 2 +- 4 files changed, 3 insertions(+), 2 deletions(-) rename {Utils => Middleware}/Passport/auth.js (87%) rename {Utils => Middleware}/Passport/config.js (100%) diff --git a/Components/User/index.js b/Components/User/index.js index d3154b3..7ec3cca 100644 --- a/Components/User/index.js +++ b/Components/User/index.js @@ -1,7 +1,7 @@ /* INCLUDES ****************************** */ const express = require('express'); const passport = require('passport'); -const { isAlreadyAuthenticated } = require('./../../Utils/Passport/auth'); +const { isAlreadyAuthenticated } = require('../../Middleware/Passport/auth'); /* **************************************** */ /* ROUTES ********************************* */ diff --git a/Utils/Passport/auth.js b/Middleware/Passport/auth.js similarity index 87% rename from Utils/Passport/auth.js rename to Middleware/Passport/auth.js index e8a39d9..61c801d 100644 --- a/Utils/Passport/auth.js +++ b/Middleware/Passport/auth.js @@ -1,5 +1,6 @@ /* AUTH FUNCTIONS ************************* */ function isAuthenticated(req, res, next) { +// TODO change names of these funtions as they clash with the req.blah name if (req.isAuthenticated()) { next(); return; diff --git a/Utils/Passport/config.js b/Middleware/Passport/config.js similarity index 100% rename from Utils/Passport/config.js rename to Middleware/Passport/config.js diff --git a/index.js b/index.js index 67a6f8f..01a4bcb 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const passport = require('passport'); const flash = require('flash'); const bodyParser = require('body-parser'); const dotenv = require('dotenv'); -const passportConfig = require('./Utils/Passport/config'); +const passportConfig = require('./Middleware/Passport/config'); /* **************************************** */ /* INCLUDE CONFIGS ************************ */