fix(types): decodedToken in secret callback

close #21
This commit is contained in:
divlo 2021-01-28 18:47:38 +01:00
parent 4d73584e4e
commit c1a9213a52

View File

@ -21,7 +21,15 @@ type SocketIOMiddleware = (
next: (err?: ExtendedError) => void
) => void
type SecretCallback = (decodedToken: null | { [key: string]: any } | string) => Promise<string>
interface CompleteDecodedToken {
header: {
alg: Algorithm
[key: string]: any
}
payload: any
}
type SecretCallback = (decodedToken: CompleteDecodedToken) => Promise<string>
export interface AuthorizeOptions {
secret: string | SecretCallback
@ -58,8 +66,8 @@ export const authorize = (options: AuthorizeOptions): SocketIOMiddleware => {
if (typeof secret === 'string') {
keySecret = secret
} else {
decodedToken = jwt.decode(encodedToken, { complete: true })
keySecret = await secret(decodedToken)
const completeDecodedToken = jwt.decode(encodedToken, { complete: true })
keySecret = await secret(completeDecodedToken as CompleteDecodedToken)
}
try {
decodedToken = jwt.verify(encodedToken, keySecret, { algorithms })