{"version":3,"file":"useEmailOtpLoginOrSignup.mjs","sources":["../../../../../../../../../web/src/ui/b2b/hooks/useEmailOtpLoginOrSignup.ts"],"sourcesContent":["import { B2BOTPsEmailLoginOrSignupResponse, StytchAPIError } from '@stytch/core/public';\n\nimport { getOtpCodeExpiration } from '../getOtpCodeExpiration';\nimport { useConfig, useGlobalReducer, useStytch } from '../GlobalContextProvider';\nimport { StytchMutationKey, useMutate } from '../utils';\n\nexport const useEmailOtpLoginOrSignup = ({ throwOnError }: { throwOnError?: boolean } = {}) => {\n  const [, dispatch] = useGlobalReducer();\n  const stytchClient = useStytch();\n  const config = useConfig();\n\n  return useMutate<\n    B2BOTPsEmailLoginOrSignupResponse,\n    StytchAPIError,\n    StytchMutationKey,\n    { email: string; organization_id: string }\n  >(\n    'stytch.otps.email.loginOrSignup',\n    (_key: string, { arg: { email, organization_id } }: { arg: { email: string; organization_id: string } }) =>\n      stytchClient.otps.email.loginOrSignup({\n        email_address: email,\n        organization_id,\n        login_template_id: config.emailOtpOptions?.loginTemplateId,\n        signup_template_id: config.emailOtpOptions?.signupTemplateId,\n        locale: config.emailOtpOptions?.locale,\n      }),\n    {\n      onSuccess: () => {\n        dispatch({ type: 'send_email_otp', codeExpiration: getOtpCodeExpiration() });\n      },\n      throwOnError,\n    },\n  );\n};\n"],"names":["useEmailOtpLoginOrSignup","throwOnError","dispatch","useGlobalReducer","stytchClient","useStytch","config","useConfig","useMutate","_key","arg","email","organization_id","otps","loginOrSignup","email_address","login_template_id","emailOtpOptions","loginTemplateId","signup_template_id","signupTemplateId","locale","onSuccess","type","codeExpiration","getOtpCodeExpiration"],"mappings":";;;;AAMO,MAAMA,2BAA2B,CAAC,EAAEC,YAAY,EAA8B,GAAG,EAAE,GAAA;IACxF,MAAM,GAAGC,SAAS,GAAGC,gBAAAA,EAAAA;AACrB,IAAA,MAAMC,YAAAA,GAAeC,SAAAA,EAAAA;AACrB,IAAA,MAAMC,MAAAA,GAASC,SAAAA,EAAAA;AAEf,IAAA,OAAOC,UAML,iCAAA,EACA,CAACC,MAAc,EAAEC,GAAAA,EAAK,EAAEC,KAAK,EAAEC,eAAe,EAAE,EAAuD,GACrGR,YAAAA,CAAaS,IAAI,CAACF,KAAK,CAACG,aAAa,CAAC;YACpCC,aAAAA,EAAeJ,KAAAA;AACfC,YAAAA,eAAAA;YACAI,iBAAAA,EAAmBV,MAAAA,CAAOW,eAAe,EAAEC,eAAAA;YAC3CC,kBAAAA,EAAoBb,MAAAA,CAAOW,eAAe,EAAEG,gBAAAA;YAC5CC,MAAAA,EAAQf,MAAAA,CAAOW,eAAe,EAAEI;SAClC,CAAA,EACF;QACEC,SAAAA,EAAW,IAAA;YACTpB,QAAAA,CAAS;gBAAEqB,IAAAA,EAAM,gBAAA;gBAAkBC,cAAAA,EAAgBC,oBAAAA;AAAuB,aAAA,CAAA;AAC5E,QAAA,CAAA;AACAxB,QAAAA;AACF,KAAA,CAAA;AAEJ;;;;"}