fix: safer isUnauthorizedError type guard

This commit is contained in:
Divlo
2023-04-02 23:04:41 +02:00
parent 03e8d51f9a
commit 71e0d82655
8 changed files with 3164 additions and 1621 deletions

View File

@@ -15,6 +15,11 @@ export class UnauthorizedError extends Error {
}
}
export const isUnauthorizedError = (error: any): error is UnauthorizedError => {
return error.data.type === 'UnauthorizedError'
export const isUnauthorizedError = (
error: unknown
): error is UnauthorizedError => {
return (
error instanceof UnauthorizedError &&
error.data.type === 'UnauthorizedError'
)
}

View File

@@ -62,7 +62,7 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => {
}
socket.encodedToken = encodedToken
let keySecret: string | null = null
let decodedToken: any
let decodedToken: any = null
if (typeof secret === 'string') {
keySecret = secret
} else {