Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sumor/token-middleware

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/token-middleware - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

4

package.json
{
"name": "@sumor/token-middleware",
"description": "A token middleware for ExpressJS.",
"version": "1.0.1",
"version": "1.1.0",
"license": "MIT",

@@ -17,3 +17,3 @@ "repository": "sumor-cloud/token-middleware",

"devDependencies": {
"@sumor/ssl-server": "^1.0.23",
"@sumor/ssl-server": "^1.1.1",
"axios": "^1.7.2",

@@ -20,0 +20,0 @@ "@jest/globals": "^29.7.0",

import Token from './Token.js'
import parseCookie from './parseCookie.js'
export default (req, res, next) => {
const cookie = parseCookie(req.headers.cookie)
req.token = new Token(id => {
let existingCookie = res.getHeader('Set-Cookie') || []
if (typeof existingCookie === 'string') {
existingCookie = [existingCookie]
const authorization = req.headers.authorization
if (authorization) {
req.token = new Token()
if (authorization.startsWith('Bearer ')) {
req.token._id = authorization.substring(7)
}
const maxAge = 100 * 24 * 60 * 60
res.setHeader('Set-Cookie', [...existingCookie, `t=${id}; Path=/; HttpOnly; Max-Age=${maxAge}`])
})
req.token._id = cookie.t || null
} else {
const cookie = parseCookie(req.headers.cookie)
req.token = new Token(id => {
let existingCookie = res.getHeader('Set-Cookie') || []
if (typeof existingCookie === 'string') {
existingCookie = [existingCookie]
}
const maxAge = 100 * 24 * 60 * 60
res.setHeader('Set-Cookie', [
...existingCookie,
`t=${id}; Path=/; HttpOnly; Max-Age=${maxAge}`
])
})
req.token._id = cookie.t || null
}
next()
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc