diff --git a/authentication/auth.js b/authentication/auth.js index 0ef3614..c305a74 100644 --- a/authentication/auth.js +++ b/authentication/auth.js @@ -16,6 +16,7 @@ module.exports = { failureRedirect: '/login' }), + localRegistration: async (req, res, next) => { try { const { body } = req @@ -44,3 +45,21 @@ module.exports = { } } } + +// Protects routes that requires logged access +const loggInRequired = async (req, res, next)=>{ + + // Assumming the email is in the session + const email = req.session.email + const data = await User.findOne({ email }) + if (data) { + next() + } else { + res.redirect("/login") + } +}); + + + + + diff --git a/routes/index.js b/routes/index.js index 787e71a..2cfbdd4 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,8 +4,11 @@ const auth = require('../authentication/index') const express = require('express') router = express.Router() - // Local login + // Local registration / Login router.post('/create/user', auth.localRegistration) + router.get('/login',(req, res, next)=>{ + res.render('login') + }) // Twitter login router.get('/login/twitter', auth.twitterAuthentication.twitterLogin) diff --git a/utils/helper.js b/utils/helper.js index f8a53d1..9da2ab9 100644 --- a/utils/helper.js +++ b/utils/helper.js @@ -67,6 +67,8 @@ const checkAccessLevel = accessKey => (verifiedToken, req, res, next) => { } } +} + module.exports = { encryptPassword, decryptPassword,