cauthy-auth 0.22.0 → 0.24.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/vue.mjs CHANGED
@@ -246,6 +246,35 @@ function createAuthClient(options = {}) {
246
246
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
247
247
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
248
248
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
249
+ mfaPush: () => post("/sign-in/mfa/push", {}, null),
250
+ async mfaPushWait(o = {}) {
251
+ const status = await new Promise((resolve) => {
252
+ if (typeof EventSource !== "function") return resolve("approved");
253
+ const source = new EventSource(`${base}/sign-in/mfa/push/events`, { withCredentials: true });
254
+ const stop = (st) => {
255
+ source.close();
256
+ resolve(st);
257
+ };
258
+ o.signal?.addEventListener("abort", () => stop("aborted"));
259
+ source.addEventListener("status", (e) => {
260
+ const st = (() => {
261
+ try {
262
+ return String(JSON.parse(e.data).status);
263
+ } catch {
264
+ return "";
265
+ }
266
+ })();
267
+ if (st && st !== "pending") stop(st);
268
+ });
269
+ source.onerror = () => {
270
+ if (source.readyState === EventSource.CLOSED) stop("expired");
271
+ };
272
+ });
273
+ if (status === "aborted") return { ok: false, error: { code: "aborted", message: "Stopped waiting." } };
274
+ if (status === "denied") return { ok: false, error: { code: "push_denied", message: "The sign-in was turned down on the phone." } };
275
+ if (status === "expired") return { ok: false, error: { code: "push_expired", message: "Nobody answered on the phone in time." } };
276
+ return post("/sign-in/mfa/push/finish", {}, null);
277
+ },
249
278
  magicLink: (f) => post("/sign-in/magic-link", { email: f.email, ...f.create ? { create: true } : {}, ...f.returnTo ? { returnTo: f.returnTo } : {} }, checkEmail(f.email), f.captchaToken),
250
279
  magicLinkVerify: (f) => post("/sign-in/magic-link/verify", { token: f.token }, null),
251
280
  emailCode: (f) => post("/sign-in/email-code", { code: f.code }, checkCode(f.code)),