mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added login redirects
This commit is contained in:
parent
a03f56028a
commit
bcf377ad56
3 changed files with 86 additions and 25 deletions
|
@ -5,14 +5,16 @@ const dbtools = require('../utils/dbtools.js')
|
|||
module.exports = function (options) {
|
||||
const { userDB, jsonResponse, exceptions } = options
|
||||
|
||||
const renderLogin = (res) => {
|
||||
const renderLogin = (req, res) => {
|
||||
if (jsonResponse) {
|
||||
res.json({
|
||||
result: 'nouser',
|
||||
msg: 'You are not logged in'
|
||||
})
|
||||
} else {
|
||||
res.render('login')
|
||||
res.render('login', {
|
||||
redirect: 'https://' + req.hostname + req.url
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +39,7 @@ module.exports = function (options) {
|
|||
|
||||
if (!sessionID) {
|
||||
logger.DebugLog(`No session ID: ${req.url}`, 'auth', 1)
|
||||
renderLogin(res)
|
||||
renderLogin(req, res)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -45,7 +47,7 @@ module.exports = function (options) {
|
|||
|
||||
if (!user) {
|
||||
logger.DebugLog(`No user:${req.url}`, 'auth', 1)
|
||||
renderLogin(res)
|
||||
renderLogin(req, res)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue