@slashid/docusaurus-theme-slashid
Version:
SlashID theme for Docusaurus.
89 lines (87 loc) • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useValidateNumber = exports.useValidateEmail = exports.getMethodText = exports.getErrorMessage = exports.filterOutOptions = void 0;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* ============================================================================
* Copyright (c) SlashID
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
const getErrorMessage = error => {
switch (error) {
case "malformed phone number":
return "The phone number you inserted is not valid";
case "maformed email address":
return "The email address you inserted is not valid";
default:
return error;
}
};
exports.getErrorMessage = getErrorMessage;
const getMethodText = (method, identifierType) => {
switch (method) {
case "webauthn":
case "webauthn_via_sms":
case "webauthn_via_email":
if (identifierType == "email_address") {
return "You'll be prompted to validate your login via your device! If you are registering for the first time, you will receive an email to verify your email address.";
}
if (identifierType == "phone_number") {
return "You'll be prompted to validate your login via your device! If you are registering for the first time, you will receive an SMS to verify your phone number.";
}
return "You'll be prompted to validate your login via your device! If you are registering for the first time you will receive a message to confirm your username first.";
case "email_link":
default:
return "We have sent you a link via email. Follow the link provided to complete your registration.";
case "sms_link":
return "We have sent you a link via text. Follow the link provided to complete your registration.";
case "otp_via_sms":
return "We sent you a code via text. Please insert it.";
}
};
exports.getMethodText = getMethodText;
const useValidateEmail = () => {
const validateEmail = _react.default.useCallback(email => {
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (String(email).toLowerCase().match(emailRegex)) {
return true;
} else {
return false;
}
}, []);
return {
validateEmail
};
};
exports.useValidateEmail = useValidateEmail;
const useValidateNumber = () => {
const validateNumber = _react.default.useCallback(number => {
const numberRegex = /^[\+](?=.*\d).{6,20}$/im;
if (String(number).toLowerCase().match(numberRegex)) {
return true;
} else {
return false;
}
}, []);
return {
validateNumber
};
};
exports.useValidateNumber = useValidateNumber;
const filterOutOptions = (identifier, options) => {
if (!options) {
return;
}
if (identifier === "email_address") {
return options.filter(option => option !== "webauthn_via_email");
}
if (identifier === "phone_number") {
return options.filter(option => option !== "webauthn_via_sms");
}
return;
};
exports.filterOutOptions = filterOutOptions;