
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
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 4 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.