mirror of https://github.com/status-im/codimd.git
Merge pull request #1609 from mic4ael/return-to-note-on-login
Better redirection after a successful login
This commit is contained in:
commit
bf5325b37f
|
@ -5,10 +5,23 @@ const config = require('../config')
|
|||
const logger = require('../logger')
|
||||
|
||||
exports.setReturnToFromReferer = function setReturnToFromReferer (req) {
|
||||
var referer = req.get('referer')
|
||||
if (!req.session) req.session = {}
|
||||
|
||||
var referer = req.get('referer')
|
||||
var refererSearchParams = new URLSearchParams(new URL(referer).search)
|
||||
var nextURL = refererSearchParams.get('next')
|
||||
|
||||
if (nextURL) {
|
||||
var isRelativeNextURL = nextURL.indexOf('://') === -1 && !nextURL.startsWith('//')
|
||||
if (isRelativeNextURL) {
|
||||
req.session.returnTo = (new URL(nextURL, config.serverURL)).toString()
|
||||
} else {
|
||||
req.session.returnTo = config.serverURL
|
||||
}
|
||||
} else {
|
||||
req.session.returnTo = referer
|
||||
}
|
||||
}
|
||||
|
||||
exports.passportGeneralCallback = function callback (accessToken, refreshToken, profile, done) {
|
||||
var stringifiedProfile = JSON.stringify(profile)
|
||||
|
|
|
@ -32,8 +32,10 @@ function errorForbidden (req, res) {
|
|||
if (req.user) {
|
||||
responseError(res, '403', 'Forbidden', 'oh no.')
|
||||
} else {
|
||||
var nextURL = new URL('', config.serverURL)
|
||||
nextURL.search = new URLSearchParams({ next: req.originalUrl })
|
||||
req.flash('error', 'You are not allowed to access this page. Maybe try logging in?')
|
||||
res.redirect(config.serverURL + '/')
|
||||
res.redirect(nextURL.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue