"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "authorize", {
    enumerable: true,
    get: function() {
        return authorize;
    }
});
const _passportjwt = require("passport-jwt");
const authorize = (settingsStore, options, logger, verify)=>{
    const strategy = new _passportjwt.Strategy(options, verify);
    return async function authorizeCallback(socket, next) {
        if (!await settingsStore.getLoginRequired()) {
            return next();
        }
        strategy.success = function success(_user) {
            next();
        };
        strategy.fail = (info)=>{
            logger.warn(`Failure authenticating SocketIO user, reason: '${info}'`, {
                reason: info
            });
            next(new Error(info));
        };
        strategy.error = (error)=>{
            logger.warn("Error authenticating SocketIO user");
            next(error);
        };
        strategy.authenticate(socket, {});
    };
};

//# sourceMappingURL=socketio.middleware.js.map