feat: update frontend to use cookie session

* use SessionMiddleware in socket.io server
* add back jwtStrategy for commands
This commit is contained in:
wancat committed 2023-09-17 12:14:30 +08:00
1 parent be5cd152a9
commit 34c277c886
13 files changed
+90 -116

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
export default function authRequired(req, res, next) {
if (req.isAuthenticated()) {
next()
return
}
res.status(401).json({
message: 'not authenticated',
})
}
+12 -15
View File
@@ -3,18 +3,15 @@ import MongoStore from 'connect-mongo'
import config from '../config.js'
export default (db) => {
console.log(db.constructor.name)
return session({
secret: config.jwtSecret,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
},
store: MongoStore.create({
mongoUrl: config.db,
collectionName: 'loginSessions',
}),
})
}
export default session({
secret: config.jwtSecret,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
},
store: MongoStore.create({
mongoUrl: config.db,
collectionName: 'loginSessions',
}),
})