fix: safer isUnauthorizedError
type guard
This commit is contained in:
parent
03e8d51f9a
commit
71e0d82655
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
build:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.3.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
|
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.3.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
release:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.3.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.3.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
|
4702
package-lock.json
generated
4702
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@ -53,38 +53,38 @@
|
||||
"jsonwebtoken": "9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "17.4.1",
|
||||
"@commitlint/config-conventional": "17.4.0",
|
||||
"@swc/cli": "0.1.57",
|
||||
"@swc/core": "1.3.25",
|
||||
"@tsconfig/strictest": "1.0.2",
|
||||
"@types/jsonwebtoken": "9.0.0",
|
||||
"@types/node": "18.11.18",
|
||||
"@types/tap": "15.0.7",
|
||||
"@typescript-eslint/eslint-plugin": "5.48.1",
|
||||
"@typescript-eslint/parser": "5.48.1",
|
||||
"axios": "1.2.2",
|
||||
"c8": "7.12.0",
|
||||
"editorconfig-checker": "4.0.2",
|
||||
"eslint": "8.31.0",
|
||||
"eslint-config-conventions": "6.0.0",
|
||||
"eslint-config-prettier": "8.6.0",
|
||||
"eslint-plugin-import": "2.26.0",
|
||||
"@commitlint/cli": "17.5.1",
|
||||
"@commitlint/config-conventional": "17.4.4",
|
||||
"@swc/cli": "0.1.62",
|
||||
"@swc/core": "1.3.44",
|
||||
"@tsconfig/strictest": "2.0.0",
|
||||
"@types/jsonwebtoken": "9.0.1",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/tap": "15.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "5.57.0",
|
||||
"@typescript-eslint/parser": "5.57.0",
|
||||
"axios": "1.3.4",
|
||||
"c8": "7.13.0",
|
||||
"editorconfig-checker": "5.0.1",
|
||||
"eslint": "8.37.0",
|
||||
"eslint-config-conventions": "8.0.0",
|
||||
"eslint-config-prettier": "8.8.0",
|
||||
"eslint-plugin-import": "2.27.5",
|
||||
"eslint-plugin-prettier": "4.2.1",
|
||||
"eslint-plugin-promise": "6.1.1",
|
||||
"eslint-plugin-unicorn": "45.0.2",
|
||||
"fastify": "4.11.0",
|
||||
"eslint-plugin-unicorn": "46.0.0",
|
||||
"fastify": "4.15.0",
|
||||
"husky": "8.0.3",
|
||||
"lint-staged": "13.1.0",
|
||||
"lint-staged": "13.2.0",
|
||||
"markdownlint-cli2": "0.6.0",
|
||||
"markdownlint-rule-relative-links": "1.1.1",
|
||||
"markdownlint-rule-relative-links": "1.1.2",
|
||||
"pinst": "3.0.0",
|
||||
"prettier": "2.8.2",
|
||||
"rimraf": "3.0.2",
|
||||
"semantic-release": "20.0.2",
|
||||
"socket.io": "4.5.4",
|
||||
"socket.io-client": "4.5.4",
|
||||
"tap": "16.3.3",
|
||||
"typescript": "4.9.4"
|
||||
"prettier": "2.8.7",
|
||||
"rimraf": "4.4.1",
|
||||
"semantic-release": "21.0.1",
|
||||
"socket.io": "4.6.1",
|
||||
"socket.io-client": "4.6.1",
|
||||
"tap": "16.3.4",
|
||||
"typescript": "5.0.3"
|
||||
}
|
||||
}
|
||||
|
@ -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