fix: safer isUnauthorizedError
type guard
This commit is contained in:
@@ -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'
|
||||
)
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user