cauthy-auth 0.8.0 → 0.9.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 +38 -1
- package/dist/client.d.ts +38 -1
- package/dist/client.js +11 -0
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +11 -0
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +47 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +47 -1
- package/dist/react.d.ts +47 -1
- package/dist/react.js +100 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +100 -0
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +11 -0
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +11 -0
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.js +11 -0
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +11 -0
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -131,6 +131,7 @@ function createAuthClient(options = {}) {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
+
const linkUrl = (provider, o = {}) => `${base}/me/identities/link/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
|
|
134
135
|
const socialUrl = (provider, o = {}) => `${base}/sign-in/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
|
|
135
136
|
const passkeyUrl = (o = {}) => {
|
|
136
137
|
const q = new URLSearchParams({ method: "passkey" });
|
|
@@ -177,6 +178,16 @@ function createAuthClient(options = {}) {
|
|
|
177
178
|
disable: (f) => post("/me/mfa/disable", { password: f.password }, null),
|
|
178
179
|
recoveryCodes: (f) => post("/me/mfa/recovery-codes", { password: f.password }, null)
|
|
179
180
|
},
|
|
181
|
+
changeEmail: (f) => post("/me/email", { email: f.email, password: f.password }, checkEmail(f.email)),
|
|
182
|
+
async identities() {
|
|
183
|
+
const body = await read("/me/identities");
|
|
184
|
+
return body && Array.isArray(body.identities) ? body.identities : [];
|
|
185
|
+
},
|
|
186
|
+
linkUrl,
|
|
187
|
+
link(provider, o) {
|
|
188
|
+
window.location.assign(linkUrl(provider, o));
|
|
189
|
+
},
|
|
190
|
+
unlink: (provider) => post("/me/identities/unlink", { provider }, null),
|
|
180
191
|
async sessions() {
|
|
181
192
|
const body = await read("/me/sessions");
|
|
182
193
|
return body && Array.isArray(body.sessions) ? body.sessions : [];
|
|
@@ -313,6 +324,15 @@ var TEXTS = {
|
|
|
313
324
|
sessions: "Where you are signed in",
|
|
314
325
|
signOutEverywhere: "Sign out everywhere",
|
|
315
326
|
unknownDevice: "Unknown device",
|
|
327
|
+
emailAddress: "Email address",
|
|
328
|
+
newEmail: "New email address",
|
|
329
|
+
changeEmail: "Change email",
|
|
330
|
+
emailSent: "We sent a link to {email}. Your address changes once you open it.",
|
|
331
|
+
linkedAccounts: "Linked accounts",
|
|
332
|
+
noLinkedAccounts: "No account is linked.",
|
|
333
|
+
linkWith: "Link",
|
|
334
|
+
unlink: "Unlink",
|
|
335
|
+
linked: "The account was linked.",
|
|
316
336
|
errors: {
|
|
317
337
|
required: "This is required.",
|
|
318
338
|
invalid_email: "That does not look like an email address.",
|
|
@@ -321,6 +341,11 @@ var TEXTS = {
|
|
|
321
341
|
unavailable: "Sign-in is unavailable right now. Try again in a moment.",
|
|
322
342
|
state_mismatch: "That sign-in could not be completed. Try again.",
|
|
323
343
|
cancelled: "The sign-in was cancelled.",
|
|
344
|
+
email_taken: "That address already has an account.",
|
|
345
|
+
email_unchanged: "That is already your address.",
|
|
346
|
+
last_sign_in_method: "Add a password or link another account first: it is your only way to sign in.",
|
|
347
|
+
identity_already_linked: "That account is linked to someone else.",
|
|
348
|
+
manual_linking_disabled: "Linking accounts is turned off for this workspace.",
|
|
324
349
|
invalid_token: "This link is not valid, or it has expired. Ask for a new one.",
|
|
325
350
|
invalid_code: "That code is not right, or it has expired.",
|
|
326
351
|
wrong_password: "The current password is not right.",
|
|
@@ -378,6 +403,15 @@ var TEXTS = {
|
|
|
378
403
|
sessions: "D\xF3nde tienes la sesi\xF3n abierta",
|
|
379
404
|
signOutEverywhere: "Cerrar sesi\xF3n en todas partes",
|
|
380
405
|
unknownDevice: "Dispositivo desconocido",
|
|
406
|
+
emailAddress: "Correo",
|
|
407
|
+
newEmail: "Correo nuevo",
|
|
408
|
+
changeEmail: "Cambiar el correo",
|
|
409
|
+
emailSent: "Enviamos un enlace a {email}. Tu correo cambia cuando lo abras.",
|
|
410
|
+
linkedAccounts: "Cuentas vinculadas",
|
|
411
|
+
noLinkedAccounts: "No hay cuentas vinculadas.",
|
|
412
|
+
linkWith: "Vincular",
|
|
413
|
+
unlink: "Desvincular",
|
|
414
|
+
linked: "La cuenta qued\xF3 vinculada.",
|
|
381
415
|
errors: {
|
|
382
416
|
required: "Este dato es obligatorio.",
|
|
383
417
|
invalid_email: "Eso no parece un correo.",
|
|
@@ -386,6 +420,11 @@ var TEXTS = {
|
|
|
386
420
|
unavailable: "No se puede entrar en este momento. Intenta de nuevo en un momento.",
|
|
387
421
|
state_mismatch: "No se pudo completar el ingreso. Intenta de nuevo.",
|
|
388
422
|
cancelled: "El ingreso se cancel\xF3.",
|
|
423
|
+
email_taken: "Ese correo ya tiene una cuenta.",
|
|
424
|
+
email_unchanged: "Ese ya es tu correo.",
|
|
425
|
+
last_sign_in_method: "Primero agrega una contrase\xF1a o vincula otra cuenta: es tu \xFAnica forma de entrar.",
|
|
426
|
+
identity_already_linked: "Esa cuenta est\xE1 vinculada a otra persona.",
|
|
427
|
+
manual_linking_disabled: "Vincular cuentas est\xE1 desactivado en este workspace.",
|
|
389
428
|
invalid_token: "Este enlace no es v\xE1lido o ya venci\xF3. Pide uno nuevo.",
|
|
390
429
|
invalid_code: "Ese c\xF3digo no es correcto o ya venci\xF3.",
|
|
391
430
|
wrong_password: "La contrase\xF1a actual no es correcta.",
|
|
@@ -745,7 +784,9 @@ function Account(props) {
|
|
|
745
784
|
const when = props.formatDate ?? ((iso) => new Date(iso).toLocaleString());
|
|
746
785
|
return /* @__PURE__ */ jsxs("div", { className: cx("account"), ...root, children: [
|
|
747
786
|
/* @__PURE__ */ jsx(ProfilePart, { props, account, onSaved: setAccount }),
|
|
787
|
+
/* @__PURE__ */ jsx(EmailPart, { props, account }),
|
|
748
788
|
account.hasPassword && /* @__PURE__ */ jsx(PasswordPart, { props }),
|
|
789
|
+
/* @__PURE__ */ jsx(LinkedPart, { props }),
|
|
749
790
|
/* @__PURE__ */ jsx(SecondStepPart, { props, account, onChanged: (mfaEnabled) => setAccount({ ...account, mfaEnabled }) }),
|
|
750
791
|
/* @__PURE__ */ jsxs("section", { className: cx("section"), children: [
|
|
751
792
|
/* @__PURE__ */ jsx("h2", { className: cx("heading"), children: t.passkeys }),
|
|
@@ -784,6 +825,65 @@ function ProfilePart({ props, account, onSaved }) {
|
|
|
784
825
|
done && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: done })
|
|
785
826
|
] });
|
|
786
827
|
}
|
|
828
|
+
function EmailPart({ props, account }) {
|
|
829
|
+
const auth = useAuth();
|
|
830
|
+
const { f, done, setDone, run, general } = useSection(props);
|
|
831
|
+
const [email, setEmail] = useState("");
|
|
832
|
+
const [password, setPassword] = useState("");
|
|
833
|
+
const submit = async (e) => {
|
|
834
|
+
e.preventDefault();
|
|
835
|
+
const r = await run(() => auth.account.changeEmail({ email, password }));
|
|
836
|
+
if (!r.ok) return;
|
|
837
|
+
setPassword("");
|
|
838
|
+
setDone(f.t.emailSent.replace("{email}", r.email));
|
|
839
|
+
};
|
|
840
|
+
return /* @__PURE__ */ jsxs("form", { className: f.cx("section"), onSubmit: submit, noValidate: true, children: [
|
|
841
|
+
/* @__PURE__ */ jsx("h2", { className: f.cx("heading"), children: f.t.emailAddress }),
|
|
842
|
+
/* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: account.email }),
|
|
843
|
+
general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
|
|
844
|
+
/* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.newEmail, value: email, autoComplete: "email", required: true, onChange: setEmail }),
|
|
845
|
+
account.hasPassword && /* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.currentPassword, value: password, autoComplete: "current-password", required: true, onChange: setPassword }),
|
|
846
|
+
/* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.changeEmail }),
|
|
847
|
+
done && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: done })
|
|
848
|
+
] });
|
|
849
|
+
}
|
|
850
|
+
function LinkedPart({ props }) {
|
|
851
|
+
const auth = useAuth();
|
|
852
|
+
const { f, run, general } = useSection(props);
|
|
853
|
+
const [linked, setLinked] = useState(null);
|
|
854
|
+
const [offered, setOffered] = useState([]);
|
|
855
|
+
const [came, setCame] = useState(null);
|
|
856
|
+
useEffect(() => {
|
|
857
|
+
void auth.account.identities().then(setLinked);
|
|
858
|
+
void auth.methods().then((m) => setOffered(m.providers));
|
|
859
|
+
const back = typeof window === "undefined" ? null : new URLSearchParams(window.location.search);
|
|
860
|
+
if (back?.get("linked")) setCame(back.get("linked"));
|
|
861
|
+
else if (back?.get("auth_error")) f.setError({ code: back.get("auth_error"), message: "That account could not be linked. Try again." });
|
|
862
|
+
}, []);
|
|
863
|
+
if (linked === null) return null;
|
|
864
|
+
const name = (id) => offered.find((p) => p.id === id)?.name ?? id;
|
|
865
|
+
const unlink = async (provider) => {
|
|
866
|
+
const r = await run(() => auth.account.unlink(provider));
|
|
867
|
+
if (r.ok) setLinked(linked.filter((x) => x.provider !== provider));
|
|
868
|
+
};
|
|
869
|
+
const here = typeof window === "undefined" ? void 0 : window.location.pathname;
|
|
870
|
+
return /* @__PURE__ */ jsxs("section", { className: f.cx("section"), children: [
|
|
871
|
+
/* @__PURE__ */ jsx("h2", { className: f.cx("heading"), children: f.t.linkedAccounts }),
|
|
872
|
+
came && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: f.t.linked }),
|
|
873
|
+
general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
|
|
874
|
+
linked.length === 0 ? /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.noLinkedAccounts }) : /* @__PURE__ */ jsx("ul", { className: f.cx("sessions"), children: linked.map((x) => /* @__PURE__ */ jsxs("li", { className: f.cx("session"), children: [
|
|
875
|
+
name(x.provider),
|
|
876
|
+
x.email ? ` \xB7 ${x.email}` : "",
|
|
877
|
+
" ",
|
|
878
|
+
/* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void unlink(x.provider), children: f.t.unlink })
|
|
879
|
+
] }, x.provider)) }),
|
|
880
|
+
offered.filter((p) => !linked.some((x) => x.provider === p.id)).map((p) => /* @__PURE__ */ jsxs(f.Button, { type: "button", className: f.cx("providerButton"), onClick: () => auth.account.link(p.id, { returnTo: here }), children: [
|
|
881
|
+
f.t.linkWith,
|
|
882
|
+
" ",
|
|
883
|
+
p.name
|
|
884
|
+
] }, p.id))
|
|
885
|
+
] });
|
|
886
|
+
}
|
|
787
887
|
function PasswordPart({ props }) {
|
|
788
888
|
const auth = useAuth();
|
|
789
889
|
const { f, done, setDone, run, general } = useSection(props);
|