throw errors instead of returning them, define interface for jwt payload

This commit is contained in:
Moriz Wahl 2021-09-28 12:11:17 +02:00 committed by einhornimmond
parent 96def721ff
commit 4ab08460a3
2 changed files with 9 additions and 6 deletions

View File

@ -20,5 +20,5 @@ export const isAuthorized: AuthChecker<any> = async ({ root, args, context, info
return result.success
}
}
return false
throw new Error('401 Unauthorized')
}

View File

@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import jwt, { JwtPayload } from 'jsonwebtoken'
import CONFIG from '../config/'
@ -9,8 +6,14 @@ interface CustomJwtPayload extends JwtPayload {
pubKey: Buffer
}
export default (token: string): any => {
if (!token) return new Error('401 Unauthorized')
type DecodedJwt = {
token: string
sessionId: number
pubKey: Buffer
}
export default (token: string): DecodedJwt => {
if (!token) throw new Error('401 Unauthorized')
let sessionId = null
let pubKey = null
try {