Merge pull request #1 from sovcik/extSocket
extending socket interface #4
This commit is contained in:
@@ -7,8 +7,12 @@ interface ExtendedError extends Error {
|
|||||||
data?: any
|
data?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ExtendedSocket extends Socket {
|
||||||
|
encodedToken?: string
|
||||||
|
decodedToken?: any
|
||||||
|
|
||||||
type SocketIOMiddleware = (
|
type SocketIOMiddleware = (
|
||||||
socket: Socket,
|
socket: ExtendedSocket,
|
||||||
next: (err?: ExtendedError) => void
|
next: (err?: ExtendedError) => void
|
||||||
) => void
|
) => void
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Store encoded JWT
|
// Store encoded JWT
|
||||||
socket = Object.assign(socket, { encodedToken: token })
|
socket.encodedToken = token
|
||||||
let payload: any
|
let payload: any
|
||||||
try {
|
try {
|
||||||
payload = jwt.verify(token, secret, { algorithms })
|
payload = jwt.verify(token, secret, { algorithms })
|
||||||
@@ -53,7 +57,7 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Store decoded JWT
|
// Store decoded JWT
|
||||||
socket = Object.assign(socket, { decodedToken: payload })
|
socket.decodedToken = payload
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user