support for ws connection without auth

This commit is contained in:
SrGooglo 2025-04-09 20:51:01 +00:00
parent 93880e8abe
commit bf2c04abc9

View File

@ -20,6 +20,10 @@ export default class API extends Server {
} }
handleWsUpgrade = async (context, token, res) => { handleWsUpgrade = async (context, token, res) => {
if (!token) {
return res.upgrade(context)
}
context = await InjectedAuth(context, token, res) context = await InjectedAuth(context, token, res)
if (!context.user) { if (!context.user) {
@ -30,13 +34,13 @@ export default class API extends Server {
return res.upgrade(context) return res.upgrade(context)
} }
handleWsConnection = (socket) => { // handleWsConnection = (socket) => {
console.log(`[WS] @${socket.context.user.username} connected`) // console.log(`[WS] @${socket.context.user.username} connected`)
} // }
handleWsDisconnect = (socket) => { // handleWsDisconnect = (socket) => {
console.log(`[WS] @${socket.context.user.username} disconnected`) // console.log(`[WS] @${socket.context.user.username} disconnected`)
} // }
contexts = { contexts = {
db: new DbManager(), db: new DbManager(),