
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
use-express-middleware
Advanced tools
The main purpose of this module is to use express
middleware for
authentication in deepstream.io
.
If you find other uses for this module, please let me know.
npm install use-express-middleware --save
✓ express-session
✓ passport.initialize()
✓ passport.session()
import Deepstream from 'deepstream.io'
import useExpressMiddleware from 'use-express-middleware'
import expressSession from 'express-session'
import passport from 'passport'
const server = new Deepstream()
// You can define this somewhere in your app and then import it both
// for express and deepstream.
// If you use a store such as redis for you sessions, you'll be able
// to run express and deepstream in two seperate processes and/or on
// two seperate ports if you so please.
const session = expressSession({
...options
})
const middleware = [session, passport.initialize(), passport.session()]
// Using a callback:
server.set('permissionHandler', {
isValidUser(connectionData, authData, callback) {
useExpressMiddleware(connectionData.headers, middleware, (req, res) => {
if(req.user) {
callback(null, req.user.id)
} else {
callback(null, 'open')
}
})
},
canPerformAction(id, message, callback) {
const user = getUserFromId(id) // pseudo code
callback(null, user.isAdmin)
}
})
// Using promises and async/await:
server.set('permissionHandler', {
isValidUser: async (connectionData, authData, callback) => {
const {req, res} = await useExpressMiddleware(connectionData.headers, middleware)
if(req.user) {
callback(null, req.user.id)
} else {
callback(null, 'open')
}
},
...
})
FAQs
Use express middleware outside of express.
The npm package use-express-middleware receives a total of 3 weekly downloads. As such, use-express-middleware popularity was classified as not popular.
We found that use-express-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.