cauthy-auth 0.24.3 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +36 -7
- package/dist/client.d.ts +36 -7
- package/dist/client.js +14 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +14 -1
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +40 -6
- package/dist/react.d.ts +40 -6
- package/dist/react.js +39 -7
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +39 -7
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +14 -1
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +14 -1
- package/dist/svelte.mjs.map +1 -1
- package/dist/{validate-B_iC-4y8.d.mts → validate-BTRit1O1.d.mts} +1 -1
- package/dist/{validate-B_iC-4y8.d.ts → validate-BTRit1O1.d.ts} +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +14 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +14 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -173,6 +173,13 @@ function checkName(value) {
|
|
|
173
173
|
if (typeof value !== "string" || value.trim().length > MAX_NAME) return { field: "name", code: "too_long", message: `Use at most ${MAX_NAME} characters.` };
|
|
174
174
|
return null;
|
|
175
175
|
}
|
|
176
|
+
var MAX_ORGANIZATION = 120;
|
|
177
|
+
function checkOrganization(value, required = false) {
|
|
178
|
+
const v = typeof value === "string" ? value.trim() : "";
|
|
179
|
+
if (v === "") return required ? { field: "organization", code: "required", message: "Enter your company's name." } : null;
|
|
180
|
+
if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
176
183
|
function checkCode(value) {
|
|
177
184
|
const v = typeof value === "string" ? value.trim() : "";
|
|
178
185
|
if (v === "") return { field: "code", code: "required", message: "Enter the code." };
|
|
@@ -279,6 +286,7 @@ function createAuthClient(options = {}) {
|
|
|
279
286
|
mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
|
|
280
287
|
mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
|
|
281
288
|
mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
|
|
289
|
+
mfaSendEmail: () => post("/sign-in/mfa/email", {}, null),
|
|
282
290
|
mfaPush: () => post("/sign-in/mfa/push", {}, null),
|
|
283
291
|
async mfaPushWait(o = {}) {
|
|
284
292
|
const status = await new Promise((resolve) => {
|
|
@@ -395,7 +403,12 @@ function createAuthClient(options = {}) {
|
|
|
395
403
|
}
|
|
396
404
|
},
|
|
397
405
|
signUp: {
|
|
398
|
-
email: (f) => post(
|
|
406
|
+
email: (f) => post(
|
|
407
|
+
"/sign-up/email",
|
|
408
|
+
{ email: f.email, password: f.password, name: f.name, organization: f.organization },
|
|
409
|
+
firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
|
|
410
|
+
f.captchaToken
|
|
411
|
+
)
|
|
399
412
|
},
|
|
400
413
|
forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
|
|
401
414
|
resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
|
|
@@ -555,6 +568,7 @@ var TEXTS = {
|
|
|
555
568
|
email: "Email",
|
|
556
569
|
password: "Password",
|
|
557
570
|
name: "Name",
|
|
571
|
+
company: "Your company's name",
|
|
558
572
|
code: "Code",
|
|
559
573
|
signIn: "Sign in",
|
|
560
574
|
signUp: "Create account",
|
|
@@ -569,6 +583,8 @@ var TEXTS = {
|
|
|
569
583
|
codeHelp: "Enter the code from your authenticator app, or a recovery code.",
|
|
570
584
|
verify: "Verify",
|
|
571
585
|
codeHelpPhone: "We send a code to your phone. Ask for it, then type it here, or use a recovery code.",
|
|
586
|
+
codeHelpEmail: "We sent a code to {to}. Type it here.",
|
|
587
|
+
sendEmailAgain: "Send the code again",
|
|
572
588
|
sendCodeSms: "Send a code by SMS to {to}",
|
|
573
589
|
sendCodeWhatsapp: "Send a code by WhatsApp to {to}",
|
|
574
590
|
codeSent: "We sent a code to {to}. Type it here.",
|
|
@@ -583,7 +599,7 @@ var TEXTS = {
|
|
|
583
599
|
removePhone: "Remove phone",
|
|
584
600
|
bySms: "SMS",
|
|
585
601
|
byWhatsapp: "WhatsApp",
|
|
586
|
-
checkEmail: "Almost there: open the link we sent to confirm your address
|
|
602
|
+
checkEmail: "Almost there: open the link we sent to confirm your address \u2014 it signs you in.",
|
|
587
603
|
backToSignIn: "Back to sign in",
|
|
588
604
|
emailMeALink: "Email me a sign-in link",
|
|
589
605
|
usePasskey: "Sign in with a passkey",
|
|
@@ -704,6 +720,7 @@ var TEXTS = {
|
|
|
704
720
|
email: "Correo",
|
|
705
721
|
password: "Contrase\xF1a",
|
|
706
722
|
name: "Nombre",
|
|
723
|
+
company: "Nombre de tu empresa",
|
|
707
724
|
code: "C\xF3digo",
|
|
708
725
|
signIn: "Entrar",
|
|
709
726
|
signUp: "Crear cuenta",
|
|
@@ -718,6 +735,8 @@ var TEXTS = {
|
|
|
718
735
|
codeHelp: "Escribe el c\xF3digo de tu aplicaci\xF3n de autenticaci\xF3n, o un c\xF3digo de recuperaci\xF3n.",
|
|
719
736
|
verify: "Verificar",
|
|
720
737
|
codeHelpPhone: "Te enviamos un c\xF3digo a tu tel\xE9fono. P\xEDdelo y escr\xEDbelo aqu\xED, o usa un c\xF3digo de recuperaci\xF3n.",
|
|
738
|
+
codeHelpEmail: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
|
|
739
|
+
sendEmailAgain: "Enviar el c\xF3digo de nuevo",
|
|
721
740
|
sendCodeSms: "Enviar un c\xF3digo por SMS a {to}",
|
|
722
741
|
sendCodeWhatsapp: "Enviar un c\xF3digo por WhatsApp a {to}",
|
|
723
742
|
codeSent: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
|
|
@@ -732,7 +751,7 @@ var TEXTS = {
|
|
|
732
751
|
removePhone: "Quitar tel\xE9fono",
|
|
733
752
|
bySms: "SMS",
|
|
734
753
|
byWhatsapp: "WhatsApp",
|
|
735
|
-
checkEmail: "
|
|
754
|
+
checkEmail: "Casi listo: abre el enlace que te enviamos para confirmar tu correo; te deja adentro.",
|
|
736
755
|
backToSignIn: "Volver a entrar",
|
|
737
756
|
emailMeALink: "Env\xEDame un enlace para entrar",
|
|
738
757
|
usePasskey: "Entrar con una llave de acceso",
|
|
@@ -1036,9 +1055,17 @@ function SignIn(props) {
|
|
|
1036
1055
|
useEffect(() => {
|
|
1037
1056
|
if (step !== "code") return;
|
|
1038
1057
|
void auth.signIn.mfaMethods().then((r) => {
|
|
1039
|
-
if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push });
|
|
1058
|
+
if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push, email: r.email });
|
|
1040
1059
|
});
|
|
1041
1060
|
}, [step]);
|
|
1061
|
+
const sendEmail = async () => {
|
|
1062
|
+
f.setBusy(true);
|
|
1063
|
+
f.setError(null);
|
|
1064
|
+
const r = await auth.signIn.mfaSendEmail();
|
|
1065
|
+
f.setBusy(false);
|
|
1066
|
+
if (!r.ok) return f.setError(r.error);
|
|
1067
|
+
setPhoneSent(r.sentTo);
|
|
1068
|
+
};
|
|
1042
1069
|
const [pushNumber, setPushNumber] = useState(0);
|
|
1043
1070
|
const pushWait = useRef(null);
|
|
1044
1071
|
useEffect(() => () => pushWait.current?.abort(), []);
|
|
@@ -1167,8 +1194,9 @@ function SignIn(props) {
|
|
|
1167
1194
|
if (step === "code") {
|
|
1168
1195
|
const to = phoneWay?.phone?.number ?? "";
|
|
1169
1196
|
return /* @__PURE__ */ jsxs("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
|
|
1170
|
-
/* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: phoneSent ? f.t.codeSent.replace("{to}", phoneSent) : phoneWay?.phone && !phoneWay.totp ? f.t.codeHelpPhone : f.t.codeHelp }),
|
|
1197
|
+
/* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: phoneSent ? f.t.codeSent.replace("{to}", phoneSent) : phoneWay?.email ? f.t.codeHelpEmail.replace("{to}", phoneWay.email.to) : phoneWay?.phone && !phoneWay.totp ? f.t.codeHelpPhone : f.t.codeHelp }),
|
|
1171
1198
|
general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
|
|
1199
|
+
phoneWay?.email && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void sendEmail(), children: f.t.sendEmailAgain }),
|
|
1172
1200
|
pushNumber > 0 ? /* @__PURE__ */ jsxs("div", { className: f.cx("notice"), role: "status", "aria-live": "polite", children: [
|
|
1173
1201
|
/* @__PURE__ */ jsx("p", { children: f.t.pushPick.replace("{n}", String(pushNumber)) }),
|
|
1174
1202
|
/* @__PURE__ */ jsx("p", { style: { fontSize: 48, fontWeight: 700, margin: "4px 0", textAlign: "center" }, children: pushNumber }),
|
|
@@ -1243,15 +1271,17 @@ function SignUp(props) {
|
|
|
1243
1271
|
const auth = useAuth();
|
|
1244
1272
|
const f = useForm(props);
|
|
1245
1273
|
const [name, setName] = useState("");
|
|
1274
|
+
const [organization, setOrganization] = useState("");
|
|
1246
1275
|
const [email, setEmail] = useState("");
|
|
1247
1276
|
const [password, setPassword] = useState("");
|
|
1248
1277
|
const [sent, setSent] = useState(false);
|
|
1249
|
-
const
|
|
1278
|
+
const methods = useMethods(auth);
|
|
1279
|
+
const challenge = useChallenge(methods?.captchaSiteKey, props.locale);
|
|
1250
1280
|
const submit = async (e) => {
|
|
1251
1281
|
e.preventDefault();
|
|
1252
1282
|
f.setBusy(true);
|
|
1253
1283
|
f.setError(null);
|
|
1254
|
-
const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
|
|
1284
|
+
const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, ...methods?.organization?.ask ? { organization } : {}, captchaToken: challenge.token });
|
|
1255
1285
|
f.setBusy(false);
|
|
1256
1286
|
challenge.renew();
|
|
1257
1287
|
if (!r.ok) return f.setError(r.error);
|
|
@@ -1267,6 +1297,7 @@ function SignUp(props) {
|
|
|
1267
1297
|
}
|
|
1268
1298
|
return /* @__PURE__ */ jsxs("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
|
|
1269
1299
|
general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
|
|
1300
|
+
methods?.organization?.ask && /* @__PURE__ */ jsx(Field, { f, name: "organization", type: "text", label: f.t.company, value: organization, autoComplete: "organization", required: methods.organization.required, onChange: setOrganization }),
|
|
1270
1301
|
/* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.name, value: name, autoComplete: "name", onChange: setName }),
|
|
1271
1302
|
/* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "username", required: true, onChange: setEmail }),
|
|
1272
1303
|
/* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.password, value: password, autoComplete: "new-password", required: true, onChange: setPassword }),
|
|
@@ -1359,6 +1390,7 @@ function VerifyEmail(props) {
|
|
|
1359
1390
|
return setState("failed");
|
|
1360
1391
|
}
|
|
1361
1392
|
void auth.verifyEmail({ token }).then((r) => {
|
|
1393
|
+
if (r.ok && r.status === "signed_in") return f.done();
|
|
1362
1394
|
if (r.ok) return setState("confirmed");
|
|
1363
1395
|
f.setError(r.error);
|
|
1364
1396
|
setState("failed");
|