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