From 0f3aadfcccd1cdaf523ef7f84677efc283de8e81 Mon Sep 17 00:00:00 2001 From: kerollos Date: Mon, 28 Oct 2019 01:30:22 +0200 Subject: [PATCH] Add customDecoded optional function customDecoded enables you to change the value of the decoded token. the decoded token is passed to the function and you can you do whatever you want with the decoded token and return it to be changed. --- lib/index.js | 8 ++++++-- types/index.d.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 977b3d1..575875b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -79,7 +79,9 @@ function noQsMethod (options) { // success handler const onSuccess = () => { - socket[options.decodedPropertyName] = decoded; + socket[options.decodedPropertyName] = options.customDecoded + ? options.customDecoded(decoded) + : decoded; socket.emit('authenticated'); if (server.$emit) { server.$emit('authenticated', socket); @@ -203,7 +205,9 @@ function authorize (options) { return auth.fail(error, socket, accept); } - socket[options.decodedPropertyName] = decoded; + socket[options.decodedPropertyName] = options.customDecoded + ? options.customDecoded(decoded) + : decoded; return auth.success(socket, accept); }; diff --git a/types/index.d.ts b/types/index.d.ts index 4ba5ba0..b216a80 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,6 +28,7 @@ declare module 'socketio-jwt' { interface IOptions { additional_auth?: (decoded: object, onSuccess: () => void, onError: (err: (string | ISocketIOError), code: string) => void) => void; + customDecoded?: (decoded: object) => object; callback?: (false | number); secret: (string | ((request: any, decodedToken: object, callback: ISocketCallback) => void));