Merge pull request #164 from kerolloz/master

Add customDecoded optional function
This commit is contained in:
Conrad Sopala 2019-10-28 08:32:15 +01:00 committed by GitHub
commit d714939e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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);
};

1
types/index.d.ts vendored
View File

@ -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));