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.js CHANGED
@@ -274,6 +274,35 @@ function createAuthClient(options = {}) {
274
274
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
275
275
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
276
276
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
277
+ mfaPush: () => post("/sign-in/mfa/push", {}, null),
278
+ async mfaPushWait(o = {}) {
279
+ const status = await new Promise((resolve) => {
280
+ if (typeof EventSource !== "function") return resolve("approved");
281
+ const source = new EventSource(`${base}/sign-in/mfa/push/events`, { withCredentials: true });
282
+ const stop = (st) => {
283
+ source.close();
284
+ resolve(st);
285
+ };
286
+ o.signal?.addEventListener("abort", () => stop("aborted"));
287
+ source.addEventListener("status", (e) => {
288
+ const st = (() => {
289
+ try {
290
+ return String(JSON.parse(e.data).status);
291
+ } catch {
292
+ return "";
293
+ }
294
+ })();
295
+ if (st && st !== "pending") stop(st);
296
+ });
297
+ source.onerror = () => {
298
+ if (source.readyState === EventSource.CLOSED) stop("expired");
299
+ };
300
+ });
301
+ if (status === "aborted") return { ok: false, error: { code: "aborted", message: "Stopped waiting." } };
302
+ if (status === "denied") return { ok: false, error: { code: "push_denied", message: "The sign-in was turned down on the phone." } };
303
+ if (status === "expired") return { ok: false, error: { code: "push_expired", message: "Nobody answered on the phone in time." } };
304
+ return post("/sign-in/mfa/push/finish", {}, null);
305
+ },
277
306
  magicLink: (f) => post("/sign-in/magic-link", { email: f.email, ...f.create ? { create: true } : {}, ...f.returnTo ? { returnTo: f.returnTo } : {} }, checkEmail(f.email), f.captchaToken),
278
307
  magicLinkVerify: (f) => post("/sign-in/magic-link/verify", { token: f.token }, null),
279
308
  emailCode: (f) => post("/sign-in/email-code", { code: f.code }, checkCode(f.code)),