@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
42 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecaptchaMethod = void 0;
var tslib_1 = require("tslib");
var identity_1 = tslib_1.__importDefault(require("../sdk/identity"));
var getConfig_1 = require("../sdk/getConfig");
var RecaptchaMethod;
(function (RecaptchaMethod) {
RecaptchaMethod["SIGN_IN"] = "SIGN_IN";
RecaptchaMethod["SIGN_UP"] = "SIGN_UP";
RecaptchaMethod["MAGIC_LINK"] = "MAGIC_LINK";
RecaptchaMethod["RESET_PASSWORD"] = "RESET_PASSWORD";
})(RecaptchaMethod || (exports.RecaptchaMethod = RecaptchaMethod = {}));
function enforceRecaptcha(caller, recaptchaToken) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var config;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, identity_1.default.getConfig()];
case 1:
config = _a.sent();
if ((0, getConfig_1.isConfigOptions)(config) &&
((caller === RecaptchaMethod.MAGIC_LINK && config.magicLinkRecaptcha) ||
(caller === RecaptchaMethod.SIGN_IN && config.signinRecaptcha) ||
(caller === RecaptchaMethod.SIGN_UP && config.signupRecaptcha) ||
(caller === RecaptchaMethod.RESET_PASSWORD && config.resetPasswordRecaptcha)) &&
!recaptchaToken) {
throw {
code: '130001',
message: 'Captcha token invalid'
};
}
else {
return [2, true];
}
return [2];
}
});
});
}
exports.default = enforceRecaptcha;
//# sourceMappingURL=enforceRecaptcha.js.map