import Passwordless from "supertokens-node/recipe/passwordless";
import { logger } from "../";

const init = () =>
  Passwordless.init({
    flowType: "USER_INPUT_CODE",
    contactMethod: "PHONE",
    smsDelivery: {
      override: (originalImplementation) => {
        return {
          ...originalImplementation,
          sendSms: async ({ userInputCode }) => {
            if (!userInputCode) {
              throw new Error("No user input code provided to sendSms");
            }

            logger.info(
              "Sending Code",
              "######################",
              "## SuperTokens Code ##",
              `##      ${userInputCode}      ##`,
              "######################"
            );
          },
        };
      },
    },
  });

export default { init };
