"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAuthorized = isAuthorized;
exports.getAuthWay = getAuthWay;
exports.authorizationResolver = authorizationResolver;
const oauth_1 = require("../components/oauth");
function isAuthorized(req) {
    if (req.yt) {
        return Boolean(Object.keys(req.yt.ytApiAuthHeaders ?? {}));
    }
    return false;
}
function getAuthWay(req) {
    if (!isAuthorized(req)) {
        return undefined;
    }
    if ((0, oauth_1.isUserOAuthLogged)(req)) {
        return 'oauth';
    }
    return req.ctx.config.allowPasswordAuth ? 'passwd' : undefined;
}
function authorizationResolver(resolver) {
    return (req, res, next) => {
        if (isAuthorized(req)) {
            next();
            return;
        }
        resolver(req, res, next);
        return;
    };
}
