mirror of
https://github.com/linuxserver/heimdalljs.git
synced 2026-02-20 05:12:24 +08:00
The current solution does not support second-level domains or IP addresses, the jwt cookie cannot be set properly and a user will be unable to login. This change allows user to publish Heimdall on IP addresses or second-level domains successfully.
28 lines
750 B
JavaScript
28 lines
750 B
JavaScript
'use strict'
|
|
|
|
const passport = require('passport')
|
|
const getRootDomain = require('../src/utils/Helpers')
|
|
|
|
module.exports = {
|
|
authorize: (req, res, next) => {
|
|
passport.authorize('jwt', { session: false }, (err, user) => {
|
|
if (err) {
|
|
req.user = null
|
|
}
|
|
|
|
if (user && !req.originalUrl.match(/\/logout/)) {
|
|
// Extend the tokens life while the user is browsing
|
|
const token = user.generateJWT()
|
|
const domain = getRootDomain(req.protocol + '://' + req.hostname + req.originalUrl) // Set cookie on top level domain for auth proxying
|
|
res.cookie('jwt', token, {
|
|
domain: domain,
|
|
maxAge: 3600000
|
|
})
|
|
}
|
|
|
|
req.user = user
|
|
next()
|
|
})(req, res, next)
|
|
}
|
|
}
|