@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
38 lines • 1.67 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import Identity from '../sdk/identity';
import { isConfigOptions } from '../sdk/getConfig';
export 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 || (RecaptchaMethod = {}));
export default function enforceRecaptcha(caller, recaptchaToken) {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Identity.getConfig()];
case 1:
config = _a.sent();
if (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];
}
});
});
}
//# sourceMappingURL=enforceRecaptcha.js.map