444d2ca7dd
* Revert "Revert "feat(structured logging): implements structured logging for backend (#1217)" (#1227)"
This reverts commit 63e6581162.
* Use pino-http instead of express pino logger
* Use correct reference to knex and do not instantiate HttpLogger prematurely
* Adds missing dependency for pino to webhook-service
* Do not instantiate middleware when passed to express
* Refactor to move logging into shared
* Copy shared packages into dockerfiles
* Build shared workspace in docker build-stage for fileimport & webhook
28 lines
888 B
JavaScript
28 lines
888 B
JavaScript
const passport = require('passport')
|
|
const { logger } = require('@/logging/logging')
|
|
|
|
/**
|
|
* Wrapper for passport.authenticate that handles success & failure scenarios correctly
|
|
* (passport.authenticate() by default doesn't, so don't use it)
|
|
* @param {import('passport').Strategy | string} strategy
|
|
* @param {import('passport').AuthenticateOptions | undefined} [options]
|
|
* @returns {import('express').Handler}
|
|
*/
|
|
function passportAuthenticate(strategy, options = undefined) {
|
|
return (req, res, next) =>
|
|
passport.authenticate(strategy, options, (err, user, info) => {
|
|
if (err) logger.error(err)
|
|
if (!user) {
|
|
const errMsg = info?.message || 'Failed to authenticate, contact server admins'
|
|
return res.redirect(`/error?message=${errMsg}`)
|
|
}
|
|
|
|
req.user = user
|
|
next()
|
|
})(req, res, next)
|
|
}
|
|
|
|
module.exports = {
|
|
passportAuthenticate
|
|
}
|