Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(localauthorization): adds local authoriation #32

Merged
merged 5 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions authentication/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
failureRedirect: '/login'
}),


localRegistration: async (req, res, next) => {
try {
const { body } = req
Expand Down Expand Up @@ -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")
}
});





5 changes: 4 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const checkAccessLevel = accessKey => (verifiedToken, req, res, next) => {
}
}

}

module.exports = {
encryptPassword,
decryptPassword,
Expand Down