mulguard 1.1.3 → 1.1.4
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/core/auth/oauth-state-store-redis.d.ts +25 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/index/index.js +1 -1
- package/dist/index/index.mjs +254 -211
- package/package.json +1 -1
package/dist/index/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ var ne = Object.defineProperty;
|
|
|
2
2
|
var se = (e, r, t) => r in e ? ne(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
3
|
var U = (e, r, t) => se(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
4
|
import { A as m, d as ie, e as oe, c as ae, g as ce } from "../actions-DeCfLtHA.mjs";
|
|
5
|
-
import { a as
|
|
5
|
+
import { a as ft, s as dt, b as ht, v as gt } from "../actions-DeCfLtHA.mjs";
|
|
6
6
|
import { v as N } from "../oauth-state-LE-qeq-K.mjs";
|
|
7
|
-
import { c as
|
|
7
|
+
import { c as pt, p as mt, k as Et, n as yt, m as kt, j as vt, l as St, e as Rt, g as At, b as Ot, i as Tt, a as It, o as _t, f as Pt, h as Ct, r as bt, d as Ut, s as Nt } from "../oauth-state-LE-qeq-K.mjs";
|
|
8
8
|
import { NextResponse as E } from "next/server";
|
|
9
9
|
const x = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
10
10
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -56,7 +56,7 @@ class le {
|
|
|
56
56
|
this.attempts.clear();
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function Or(e) {
|
|
60
60
|
return new le(e);
|
|
61
61
|
}
|
|
62
62
|
const fe = {
|
|
@@ -74,7 +74,7 @@ function H(e) {
|
|
|
74
74
|
...e
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function Tr(e, r) {
|
|
78
78
|
const t = H(r);
|
|
79
79
|
for (const [n, s] of Object.entries(t))
|
|
80
80
|
s && e.set(n, s);
|
|
@@ -112,7 +112,7 @@ const ge = /* @__PURE__ */ new Set([
|
|
|
112
112
|
"guest",
|
|
113
113
|
"user"
|
|
114
114
|
]), we = /012|123|234|345|456|567|678|789|abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz/i, pe = 8, me = 128;
|
|
115
|
-
function
|
|
115
|
+
function Ir(e, r = pe) {
|
|
116
116
|
if (typeof e != "string" || !e)
|
|
117
117
|
return { valid: !1, error: "Password is required" };
|
|
118
118
|
if (e.length < r)
|
|
@@ -185,7 +185,7 @@ function X(e, r) {
|
|
|
185
185
|
function xr(e) {
|
|
186
186
|
return e.valid === !0 && e.sanitized !== void 0;
|
|
187
187
|
}
|
|
188
|
-
class
|
|
188
|
+
class Oe {
|
|
189
189
|
constructor() {
|
|
190
190
|
U(this, "tokens", /* @__PURE__ */ new Map());
|
|
191
191
|
}
|
|
@@ -206,11 +206,11 @@ class Te {
|
|
|
206
206
|
this.tokens.clear();
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
class
|
|
209
|
+
class Te {
|
|
210
210
|
constructor(r, t = 32) {
|
|
211
211
|
U(this, "store");
|
|
212
212
|
U(this, "tokenLength");
|
|
213
|
-
this.store = r || new
|
|
213
|
+
this.store = r || new Oe(), this.tokenLength = t;
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Generate CSRF token
|
|
@@ -243,9 +243,9 @@ class Ie {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
function Dr(e) {
|
|
246
|
-
return new
|
|
246
|
+
return new Te(e);
|
|
247
247
|
}
|
|
248
|
-
function
|
|
248
|
+
function Ie(e) {
|
|
249
249
|
if (typeof e != "string")
|
|
250
250
|
return "";
|
|
251
251
|
const r = {
|
|
@@ -260,10 +260,10 @@ function Oe(e) {
|
|
|
260
260
|
function Lr(e) {
|
|
261
261
|
return typeof e != "string" ? "" : e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/on\w+\s*=\s*["'][^"']*["']/gi, "").replace(/javascript:/gi, "");
|
|
262
262
|
}
|
|
263
|
-
function Vr(e) {
|
|
264
|
-
return typeof e != "string" ? "" : Oe(e.trim());
|
|
265
|
-
}
|
|
266
263
|
function Mr(e) {
|
|
264
|
+
return typeof e != "string" ? "" : Ie(e.trim());
|
|
265
|
+
}
|
|
266
|
+
function Vr(e) {
|
|
267
267
|
return typeof e != "string" ? !1 : [
|
|
268
268
|
/<script/i,
|
|
269
269
|
/javascript:/i,
|
|
@@ -413,11 +413,11 @@ function be(e, r, t, n) {
|
|
|
413
413
|
state: n
|
|
414
414
|
});
|
|
415
415
|
if (s.defaultParams)
|
|
416
|
-
for (const [
|
|
417
|
-
a.append(
|
|
416
|
+
for (const [l, f] of Object.entries(s.defaultParams))
|
|
417
|
+
a.append(l, f);
|
|
418
418
|
if (r.params)
|
|
419
|
-
for (const [
|
|
420
|
-
a.set(
|
|
419
|
+
for (const [l, f] of Object.entries(r.params))
|
|
420
|
+
a.set(l, f);
|
|
421
421
|
return `${s.authorizationUrl}?${a.toString()}`;
|
|
422
422
|
}
|
|
423
423
|
async function Ue(e, r, t, n) {
|
|
@@ -445,14 +445,14 @@ async function Ue(e, r, t, n) {
|
|
|
445
445
|
body: i.toString()
|
|
446
446
|
});
|
|
447
447
|
if (!o.ok) {
|
|
448
|
-
const
|
|
449
|
-
let
|
|
448
|
+
const l = await o.text();
|
|
449
|
+
let f = `Failed to exchange code for tokens: ${l}`;
|
|
450
450
|
try {
|
|
451
|
-
const w = JSON.parse(
|
|
452
|
-
|
|
451
|
+
const w = JSON.parse(l);
|
|
452
|
+
f = w.error_description ?? w.error ?? f;
|
|
453
453
|
} catch {
|
|
454
454
|
}
|
|
455
|
-
throw new Error(
|
|
455
|
+
throw new Error(f);
|
|
456
456
|
}
|
|
457
457
|
const a = await o.json();
|
|
458
458
|
if (!Ne(a))
|
|
@@ -501,9 +501,9 @@ async function xe(e, r, t) {
|
|
|
501
501
|
case "github":
|
|
502
502
|
return await Le(r, t);
|
|
503
503
|
case "apple":
|
|
504
|
-
return Ve(r);
|
|
505
|
-
case "facebook":
|
|
506
504
|
return Me(r);
|
|
505
|
+
case "facebook":
|
|
506
|
+
return Ve(r);
|
|
507
507
|
default:
|
|
508
508
|
return je(r);
|
|
509
509
|
}
|
|
@@ -542,7 +542,7 @@ async function Le(e, r) {
|
|
|
542
542
|
rawProfile: n
|
|
543
543
|
};
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function Me(e) {
|
|
546
546
|
const r = e.name, t = r ? `${r.firstName ?? ""} ${r.lastName ?? ""}`.trim() : "";
|
|
547
547
|
return {
|
|
548
548
|
id: String(e.sub ?? ""),
|
|
@@ -552,7 +552,7 @@ function Ve(e) {
|
|
|
552
552
|
rawProfile: e
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
|
-
function
|
|
555
|
+
function Ve(e) {
|
|
556
556
|
var t;
|
|
557
557
|
const r = e.picture;
|
|
558
558
|
return {
|
|
@@ -600,6 +600,48 @@ class ze {
|
|
|
600
600
|
function $e() {
|
|
601
601
|
return new ze();
|
|
602
602
|
}
|
|
603
|
+
function Zr(e, r = "mulguard:oauth:state:") {
|
|
604
|
+
const t = (s) => `${r}${s}`, n = async (s) => {
|
|
605
|
+
const i = t(s);
|
|
606
|
+
await e.del(i);
|
|
607
|
+
};
|
|
608
|
+
return {
|
|
609
|
+
async set(s, i, o) {
|
|
610
|
+
const a = t(s), l = JSON.stringify(i);
|
|
611
|
+
await e.set(a, l, "EX", Math.floor(o / 1e3));
|
|
612
|
+
},
|
|
613
|
+
async get(s) {
|
|
614
|
+
const i = t(s), o = await e.get(i);
|
|
615
|
+
if (!o)
|
|
616
|
+
return null;
|
|
617
|
+
try {
|
|
618
|
+
const a = JSON.parse(o);
|
|
619
|
+
return a.expiresAt < Date.now() ? (await n(s), null) : a;
|
|
620
|
+
} catch {
|
|
621
|
+
return await n(s), null;
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
async delete(s) {
|
|
625
|
+
await n(s);
|
|
626
|
+
},
|
|
627
|
+
async cleanup() {
|
|
628
|
+
try {
|
|
629
|
+
const s = await e.keys(`${r}*`), i = Date.now();
|
|
630
|
+
for (const o of s) {
|
|
631
|
+
const a = await e.get(o);
|
|
632
|
+
if (a)
|
|
633
|
+
try {
|
|
634
|
+
JSON.parse(a).expiresAt < i && await e.del(o);
|
|
635
|
+
} catch {
|
|
636
|
+
await e.del(o);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
} catch (s) {
|
|
640
|
+
console.warn("[Mulguard] OAuth state cleanup warning:", s);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
603
645
|
function D(e) {
|
|
604
646
|
return e.success === !0 && e.user !== void 0 && e.session !== void 0;
|
|
605
647
|
}
|
|
@@ -611,49 +653,49 @@ function qe(e = {}) {
|
|
|
611
653
|
level: t = We,
|
|
612
654
|
context: n,
|
|
613
655
|
formatter: s = Be
|
|
614
|
-
} = e, i = (a) => r && a >= t, o = (a,
|
|
656
|
+
} = e, i = (a) => r && a >= t, o = (a, l, f, w) => ({
|
|
615
657
|
level: a,
|
|
616
|
-
message:
|
|
658
|
+
message: l,
|
|
617
659
|
timestamp: /* @__PURE__ */ new Date(),
|
|
618
660
|
context: n,
|
|
619
|
-
data:
|
|
661
|
+
data: f ? He(f) : void 0,
|
|
620
662
|
error: w
|
|
621
663
|
});
|
|
622
664
|
return {
|
|
623
|
-
debug: (a,
|
|
665
|
+
debug: (a, l) => {
|
|
624
666
|
if (i(
|
|
625
667
|
0
|
|
626
668
|
/* DEBUG */
|
|
627
669
|
)) {
|
|
628
|
-
const
|
|
629
|
-
console.debug(s(
|
|
670
|
+
const f = o(0, a, l);
|
|
671
|
+
console.debug(s(f));
|
|
630
672
|
}
|
|
631
673
|
},
|
|
632
|
-
info: (a,
|
|
674
|
+
info: (a, l) => {
|
|
633
675
|
if (i(
|
|
634
676
|
1
|
|
635
677
|
/* INFO */
|
|
636
678
|
)) {
|
|
637
|
-
const
|
|
638
|
-
console.info(s(
|
|
679
|
+
const f = o(1, a, l);
|
|
680
|
+
console.info(s(f));
|
|
639
681
|
}
|
|
640
682
|
},
|
|
641
|
-
warn: (a,
|
|
683
|
+
warn: (a, l) => {
|
|
642
684
|
if (i(
|
|
643
685
|
2
|
|
644
686
|
/* WARN */
|
|
645
687
|
)) {
|
|
646
|
-
const
|
|
647
|
-
console.warn(s(
|
|
688
|
+
const f = o(2, a, l);
|
|
689
|
+
console.warn(s(f));
|
|
648
690
|
}
|
|
649
691
|
},
|
|
650
|
-
error: (a,
|
|
692
|
+
error: (a, l) => {
|
|
651
693
|
if (i(
|
|
652
694
|
3
|
|
653
695
|
/* ERROR */
|
|
654
696
|
)) {
|
|
655
|
-
const
|
|
656
|
-
console.error(s(g)),
|
|
697
|
+
const f = l instanceof Error ? l : void 0, w = l instanceof Error ? void 0 : l, g = o(3, a, w, f);
|
|
698
|
+
console.error(s(g)), f && console.error(f);
|
|
657
699
|
}
|
|
658
700
|
}
|
|
659
701
|
};
|
|
@@ -678,27 +720,27 @@ function He(e) {
|
|
|
678
720
|
t[n] = s;
|
|
679
721
|
return t;
|
|
680
722
|
}
|
|
681
|
-
const
|
|
723
|
+
const I = qe();
|
|
682
724
|
function Ge(e, r, t, n = {}) {
|
|
683
725
|
const {
|
|
684
726
|
enabled: s = !0,
|
|
685
727
|
maxRetries: i = 1,
|
|
686
728
|
retryDelay: o = 1e3,
|
|
687
729
|
rateLimit: a = 3,
|
|
688
|
-
autoSignOutOnFailure:
|
|
689
|
-
redirectToLogin:
|
|
730
|
+
autoSignOutOnFailure: l = !0,
|
|
731
|
+
redirectToLogin: f = "/login",
|
|
690
732
|
autoRedirectOnFailure: w = !0
|
|
691
733
|
} = n;
|
|
692
734
|
let g = null, A = !1;
|
|
693
735
|
const S = [], v = [], y = 60 * 1e3;
|
|
694
|
-
let h = 0,
|
|
695
|
-
const L = 2,
|
|
736
|
+
let h = 0, T = !1, _ = null;
|
|
737
|
+
const L = 2, M = 60 * 1e3;
|
|
696
738
|
function c() {
|
|
697
739
|
const k = Date.now();
|
|
698
|
-
if (
|
|
740
|
+
if (T && _) {
|
|
699
741
|
if (k < _)
|
|
700
742
|
return !1;
|
|
701
|
-
|
|
743
|
+
T = !1, _ = null, h = 0;
|
|
702
744
|
}
|
|
703
745
|
for (; v.length > 0; ) {
|
|
704
746
|
const p = v[0];
|
|
@@ -710,10 +752,10 @@ function Ge(e, r, t, n = {}) {
|
|
|
710
752
|
return v.length >= a ? !1 : (v.push(k), !0);
|
|
711
753
|
}
|
|
712
754
|
function u() {
|
|
713
|
-
h++, h >= L && (
|
|
755
|
+
h++, h >= L && (T = !0, _ = Date.now() + M, process.env.NODE_ENV === "development" && console.warn("[TokenRefreshManager] Circuit breaker opened - too many consecutive failures"));
|
|
714
756
|
}
|
|
715
757
|
function d() {
|
|
716
|
-
h = 0,
|
|
758
|
+
h = 0, T = !1, _ = null;
|
|
717
759
|
}
|
|
718
760
|
async function R(k = 1) {
|
|
719
761
|
if (!s)
|
|
@@ -760,10 +802,10 @@ function Ge(e, r, t, n = {}) {
|
|
|
760
802
|
}
|
|
761
803
|
async function W(k) {
|
|
762
804
|
try {
|
|
763
|
-
if (n.onTokenRefreshFailed && await Promise.resolve(n.onTokenRefreshFailed(k)),
|
|
805
|
+
if (n.onTokenRefreshFailed && await Promise.resolve(n.onTokenRefreshFailed(k)), l && (await t(), await r(), w && typeof window < "u")) {
|
|
764
806
|
let p = !0;
|
|
765
807
|
if (n.onBeforeRedirect && (p = await Promise.resolve(n.onBeforeRedirect(k))), p) {
|
|
766
|
-
const b = new URL(
|
|
808
|
+
const b = new URL(f, window.location.origin);
|
|
767
809
|
b.searchParams.set("reason", "session_expired"), b.searchParams.set("redirect", window.location.pathname + window.location.search), window.location.href = b.toString();
|
|
768
810
|
}
|
|
769
811
|
}
|
|
@@ -843,7 +885,7 @@ function Je() {
|
|
|
843
885
|
function Ye(e) {
|
|
844
886
|
const { sessionConfig: r, cacheTtl: t, getSessionAction: n, onSessionExpired: s, onError: i } = e, o = r.cookieName ?? "__mulguard_session";
|
|
845
887
|
let a = null;
|
|
846
|
-
const
|
|
888
|
+
const l = async () => {
|
|
847
889
|
const y = Date.now();
|
|
848
890
|
if (a && y - a.timestamp < t)
|
|
849
891
|
return a.session;
|
|
@@ -854,41 +896,41 @@ function Ye(e) {
|
|
|
854
896
|
return a = { session: h, timestamp: y }, h;
|
|
855
897
|
h && !N(h) && (await w(), a = null);
|
|
856
898
|
} catch (h) {
|
|
857
|
-
|
|
899
|
+
I.debug("getSession error", { error: h }), i && await i(h instanceof Error ? h : new Error(String(h)), "getSession"), a = null;
|
|
858
900
|
}
|
|
859
901
|
try {
|
|
860
902
|
const h = await ce(o);
|
|
861
903
|
if (h)
|
|
862
904
|
try {
|
|
863
|
-
const
|
|
864
|
-
if (N(
|
|
865
|
-
return
|
|
905
|
+
const T = JSON.parse(h);
|
|
906
|
+
if (N(T))
|
|
907
|
+
return T.expiresAt && new Date(T.expiresAt) < /* @__PURE__ */ new Date() ? (s && await s(T), await w(), a = null, null) : (a = { session: T, timestamp: y }, T);
|
|
866
908
|
await w(), a = null;
|
|
867
909
|
} catch {
|
|
868
910
|
await w(), a = null;
|
|
869
911
|
}
|
|
870
912
|
} catch (h) {
|
|
871
|
-
const
|
|
872
|
-
!
|
|
913
|
+
const T = h instanceof Error ? h.message : String(h);
|
|
914
|
+
!T.includes("request scope") && !T.includes("cookies") && (I.warn("getSession cookie error", { error: h }), i && await i(
|
|
873
915
|
h instanceof Error ? h : new Error(String(h)),
|
|
874
916
|
"getSession.cookie"
|
|
875
917
|
));
|
|
876
918
|
}
|
|
877
919
|
return null;
|
|
878
|
-
},
|
|
920
|
+
}, f = async (y) => {
|
|
879
921
|
if (!N(y))
|
|
880
922
|
return {
|
|
881
923
|
success: !1,
|
|
882
924
|
error: "Invalid session structure"
|
|
883
925
|
};
|
|
884
926
|
try {
|
|
885
|
-
const h = typeof y == "object" && "token" in y ? String(y.token) : JSON.stringify(y),
|
|
927
|
+
const h = typeof y == "object" && "token" in y ? String(y.token) : JSON.stringify(y), T = oe(o, h, r), _ = await ae(T);
|
|
886
928
|
return _.success && (a = { session: y, timestamp: Date.now() }), _;
|
|
887
929
|
} catch (h) {
|
|
888
|
-
const
|
|
889
|
-
return
|
|
930
|
+
const T = h instanceof Error ? h.message : "Failed to set session";
|
|
931
|
+
return I.error("setSession error", { error: h }), i && await i(h instanceof Error ? h : new Error(String(h)), "setSession"), {
|
|
890
932
|
success: !1,
|
|
891
|
-
error:
|
|
933
|
+
error: T
|
|
892
934
|
};
|
|
893
935
|
}
|
|
894
936
|
}, w = async () => {
|
|
@@ -898,19 +940,19 @@ function Ye(e) {
|
|
|
898
940
|
domain: r.domain
|
|
899
941
|
}), a = null;
|
|
900
942
|
} catch (y) {
|
|
901
|
-
|
|
943
|
+
I.warn("clearSessionCookie error", { error: y });
|
|
902
944
|
}
|
|
903
945
|
}, g = async () => {
|
|
904
|
-
const y = await
|
|
946
|
+
const y = await l();
|
|
905
947
|
return y != null && y.accessToken && typeof y.accessToken == "string" ? y.accessToken : null;
|
|
906
948
|
};
|
|
907
949
|
return {
|
|
908
|
-
getSession:
|
|
909
|
-
setSession:
|
|
950
|
+
getSession: l,
|
|
951
|
+
setSession: f,
|
|
910
952
|
clearSessionCookie: w,
|
|
911
953
|
getAccessToken: g,
|
|
912
954
|
getRefreshToken: async () => {
|
|
913
|
-
const y = await
|
|
955
|
+
const y = await l();
|
|
914
956
|
return y != null && y.refreshToken && typeof y.refreshToken == "string" ? y.refreshToken : null;
|
|
915
957
|
},
|
|
916
958
|
hasValidTokens: async () => !!await g(),
|
|
@@ -961,17 +1003,17 @@ function Qe(e) {
|
|
|
961
1003
|
}, s = await e.actions.signIn.email(n);
|
|
962
1004
|
if (D(s)) {
|
|
963
1005
|
const i = await e.saveSessionAfterAuth(s);
|
|
964
|
-
!i.success && i.warning &&
|
|
1006
|
+
!i.success && i.warning && I.warn("Session save warning", { warning: i.warning });
|
|
965
1007
|
}
|
|
966
|
-
return s.success ?
|
|
1008
|
+
return s.success ? I.info("Sign in successful", {
|
|
967
1009
|
email: n.email.substring(0, 3) + "***"
|
|
968
|
-
}) :
|
|
1010
|
+
}) : I.warn("Sign in failed", {
|
|
969
1011
|
email: n.email.substring(0, 3) + "***",
|
|
970
1012
|
errorCode: s.errorCode
|
|
971
1013
|
}), s;
|
|
972
1014
|
} catch (t) {
|
|
973
1015
|
const n = t instanceof Error ? t.message : "Sign in failed";
|
|
974
|
-
return
|
|
1016
|
+
return I.error("Sign in error", { error: n, context: "signIn.email" }), e.onError && await e.onError(
|
|
975
1017
|
t instanceof Error ? t : new Error(String(t)),
|
|
976
1018
|
"signIn.email"
|
|
977
1019
|
), {
|
|
@@ -999,7 +1041,7 @@ function Ze(e, r) {
|
|
|
999
1041
|
"OAuth sign in is not configured. Either provide oauth action in signIn, or configure providers.oauth in config."
|
|
1000
1042
|
);
|
|
1001
1043
|
const i = await e.actions.signIn.oauth(s);
|
|
1002
|
-
return await r(i.state, s),
|
|
1044
|
+
return await r(i.state, s), I.info("OAuth sign in initiated", { provider: s }), i;
|
|
1003
1045
|
};
|
|
1004
1046
|
}
|
|
1005
1047
|
function er(e) {
|
|
@@ -1033,15 +1075,15 @@ function er(e) {
|
|
|
1033
1075
|
const s = await e.actions.signIn.otp(n.sanitized, t);
|
|
1034
1076
|
if (D(s)) {
|
|
1035
1077
|
const i = await e.saveSessionAfterAuth(s);
|
|
1036
|
-
!i.success && i.warning &&
|
|
1078
|
+
!i.success && i.warning && I.warn("Session save warning", { warning: i.warning });
|
|
1037
1079
|
}
|
|
1038
|
-
return s.success ?
|
|
1080
|
+
return s.success ? I.info("OTP sign in successful", {
|
|
1039
1081
|
email: n.sanitized.substring(0, 3) + "***"
|
|
1040
|
-
}) :
|
|
1082
|
+
}) : I.warn("OTP sign in failed", {
|
|
1041
1083
|
email: n.sanitized.substring(0, 3) + "***"
|
|
1042
1084
|
}), s;
|
|
1043
1085
|
} catch (s) {
|
|
1044
|
-
return
|
|
1086
|
+
return I.error("OTP sign in error", {
|
|
1045
1087
|
error: s instanceof Error ? s.message : "Unknown error",
|
|
1046
1088
|
context: "signIn.otp"
|
|
1047
1089
|
}), e.onError && await e.onError(
|
|
@@ -1063,7 +1105,7 @@ function rr(e) {
|
|
|
1063
1105
|
const t = await e.actions.signIn.passkey(r);
|
|
1064
1106
|
if (D(t)) {
|
|
1065
1107
|
const n = await e.saveSessionAfterAuth(t);
|
|
1066
|
-
!n.success && n.warning &&
|
|
1108
|
+
!n.success && n.warning && I.warn("Session save warning", { warning: n.warning });
|
|
1067
1109
|
}
|
|
1068
1110
|
return t;
|
|
1069
1111
|
} catch (t) {
|
|
@@ -1079,10 +1121,10 @@ function rr(e) {
|
|
|
1079
1121
|
}
|
|
1080
1122
|
function tr(e, r) {
|
|
1081
1123
|
const t = Qe(e), n = Ze(e, r), s = er(e), i = rr(e);
|
|
1082
|
-
return Object.assign(async (
|
|
1083
|
-
if (!
|
|
1124
|
+
return Object.assign(async (l, f) => {
|
|
1125
|
+
if (!l || typeof l != "string")
|
|
1084
1126
|
throw new Error("Provider is required");
|
|
1085
|
-
const w = X(
|
|
1127
|
+
const w = X(l, {
|
|
1086
1128
|
maxLength: 50,
|
|
1087
1129
|
allowHtml: !1,
|
|
1088
1130
|
required: !0
|
|
@@ -1093,22 +1135,22 @@ function tr(e, r) {
|
|
|
1093
1135
|
if (g === "google" || g === "github" || g === "apple" || g === "facebook" || typeof g == "string" && !["credentials", "otp", "passkey"].includes(g))
|
|
1094
1136
|
return n(g);
|
|
1095
1137
|
if (g === "credentials")
|
|
1096
|
-
return !
|
|
1138
|
+
return !f || !("email" in f) || !("password" in f) ? {
|
|
1097
1139
|
success: !1,
|
|
1098
1140
|
error: "Credentials are required",
|
|
1099
1141
|
errorCode: m.VALIDATION_ERROR
|
|
1100
|
-
} : t(
|
|
1142
|
+
} : t(f);
|
|
1101
1143
|
if (g === "otp") {
|
|
1102
|
-
if (!
|
|
1144
|
+
if (!f || !("email" in f))
|
|
1103
1145
|
return {
|
|
1104
1146
|
success: !1,
|
|
1105
1147
|
error: "Email is required",
|
|
1106
1148
|
errorCode: m.VALIDATION_ERROR
|
|
1107
1149
|
};
|
|
1108
|
-
const A =
|
|
1150
|
+
const A = f;
|
|
1109
1151
|
return s(A.email, A.code);
|
|
1110
1152
|
}
|
|
1111
|
-
return g === "passkey" ? i(
|
|
1153
|
+
return g === "passkey" ? i(f) : {
|
|
1112
1154
|
success: !1,
|
|
1113
1155
|
error: "Invalid provider",
|
|
1114
1156
|
errorCode: m.VALIDATION_ERROR
|
|
@@ -1128,7 +1170,7 @@ function nr(e) {
|
|
|
1128
1170
|
const t = await e.actions.signUp(r);
|
|
1129
1171
|
if (D(t)) {
|
|
1130
1172
|
const n = await e.saveSessionAfterAuth(t);
|
|
1131
|
-
!n.success && n.warning &&
|
|
1173
|
+
!n.success && n.warning && I.warn("Session save warning", { warning: n.warning });
|
|
1132
1174
|
}
|
|
1133
1175
|
return t;
|
|
1134
1176
|
} catch (t) {
|
|
@@ -1152,12 +1194,12 @@ function sr(e, r) {
|
|
|
1152
1194
|
errorCode: m.VALIDATION_ERROR
|
|
1153
1195
|
};
|
|
1154
1196
|
try {
|
|
1155
|
-
const o = i.redirectUri ?? `${e.baseUrl}/api/auth/callback/${t}`, a = await Ue(t, i, n, o),
|
|
1156
|
-
id:
|
|
1157
|
-
email:
|
|
1158
|
-
name:
|
|
1159
|
-
avatar:
|
|
1160
|
-
emailVerified:
|
|
1197
|
+
const o = i.redirectUri ?? `${e.baseUrl}/api/auth/callback/${t}`, a = await Ue(t, i, n, o), l = await Fe(t, a.access_token), f = {
|
|
1198
|
+
id: l.id,
|
|
1199
|
+
email: l.email,
|
|
1200
|
+
name: l.name,
|
|
1201
|
+
avatar: l.avatar,
|
|
1202
|
+
emailVerified: l.emailVerified,
|
|
1161
1203
|
provider: t,
|
|
1162
1204
|
accessToken: a.access_token,
|
|
1163
1205
|
refreshToken: a.refresh_token,
|
|
@@ -1168,12 +1210,12 @@ function sr(e, r) {
|
|
|
1168
1210
|
token_type: a.token_type,
|
|
1169
1211
|
id_token: a.id_token
|
|
1170
1212
|
},
|
|
1171
|
-
rawProfile:
|
|
1213
|
+
rawProfile: l.rawProfile
|
|
1172
1214
|
};
|
|
1173
1215
|
if (e.callbacks.onOAuthUser) {
|
|
1174
1216
|
const w = await q(
|
|
1175
1217
|
e.callbacks.onOAuthUser,
|
|
1176
|
-
[
|
|
1218
|
+
[f, t],
|
|
1177
1219
|
e.onError
|
|
1178
1220
|
);
|
|
1179
1221
|
if (!w)
|
|
@@ -1182,7 +1224,7 @@ function sr(e, r) {
|
|
|
1182
1224
|
error: "Failed to create or retrieve user",
|
|
1183
1225
|
errorCode: m.VALIDATION_ERROR
|
|
1184
1226
|
};
|
|
1185
|
-
const g = e.createSession(w,
|
|
1227
|
+
const g = e.createSession(w, f, a);
|
|
1186
1228
|
return await e.saveSession(g), e.callbacks.onSignIn && await q(
|
|
1187
1229
|
e.callbacks.onSignIn,
|
|
1188
1230
|
[g.user, g],
|
|
@@ -1195,7 +1237,7 @@ function sr(e, r) {
|
|
|
1195
1237
|
errorCode: m.VALIDATION_ERROR
|
|
1196
1238
|
};
|
|
1197
1239
|
} catch (o) {
|
|
1198
|
-
return
|
|
1240
|
+
return I.error("OAuth callback failed", { provider: t, error: o }), {
|
|
1199
1241
|
success: !1,
|
|
1200
1242
|
error: o instanceof Error ? o.message : "OAuth callback failed",
|
|
1201
1243
|
errorCode: m.NETWORK_ERROR
|
|
@@ -1226,33 +1268,33 @@ function ir(e, r, t, n) {
|
|
|
1226
1268
|
return { url: n(s, i, r, o), state: o };
|
|
1227
1269
|
};
|
|
1228
1270
|
}
|
|
1229
|
-
function
|
|
1230
|
-
var L,
|
|
1271
|
+
function et(e) {
|
|
1272
|
+
var L, M;
|
|
1231
1273
|
const r = {
|
|
1232
1274
|
...Ke(),
|
|
1233
1275
|
...e.session
|
|
1234
1276
|
}, t = e.actions, n = e.callbacks || {}, s = ((L = e.providers) == null ? void 0 : L.oauth) || {}, i = Je(), o = {
|
|
1235
1277
|
...Xe(),
|
|
1236
1278
|
...e.tokenRefresh
|
|
1237
|
-
}, a = ((
|
|
1279
|
+
}, a = ((M = e.session) == null ? void 0 : M.cacheTtl) ?? e.sessionCacheTtl ?? 5e3, l = e.oauthStateStore || $e(), f = { ...t }, w = async (c, u) => {
|
|
1238
1280
|
const d = {
|
|
1239
1281
|
provider: u,
|
|
1240
1282
|
expiresAt: Date.now() + 6e5
|
|
1241
1283
|
// 10 minutes
|
|
1242
1284
|
};
|
|
1243
|
-
await Promise.resolve(
|
|
1285
|
+
await Promise.resolve(l.set(c, d, 10 * 60 * 1e3)), l.cleanup && await Promise.resolve(l.cleanup());
|
|
1244
1286
|
}, g = async (c, u) => {
|
|
1245
|
-
const d = await Promise.resolve(
|
|
1246
|
-
return d ? d.expiresAt < Date.now() ? (await Promise.resolve(
|
|
1287
|
+
const d = await Promise.resolve(l.get(c));
|
|
1288
|
+
return d ? d.expiresAt < Date.now() ? (await Promise.resolve(l.delete(c)), !1) : d.provider !== u ? !1 : (await Promise.resolve(l.delete(c)), !0) : !1;
|
|
1247
1289
|
}, A = ir(
|
|
1248
1290
|
s,
|
|
1249
1291
|
i,
|
|
1250
1292
|
_e,
|
|
1251
1293
|
be
|
|
1252
1294
|
);
|
|
1253
|
-
if (A && !
|
|
1254
|
-
const c =
|
|
1255
|
-
|
|
1295
|
+
if (A && !f.signIn.oauth) {
|
|
1296
|
+
const c = f.signIn;
|
|
1297
|
+
f.signIn = {
|
|
1256
1298
|
...c,
|
|
1257
1299
|
oauth: async (u) => {
|
|
1258
1300
|
const d = await A(u);
|
|
@@ -1260,7 +1302,7 @@ function Zr(e) {
|
|
|
1260
1302
|
}
|
|
1261
1303
|
};
|
|
1262
1304
|
}
|
|
1263
|
-
if (!
|
|
1305
|
+
if (!f.signIn || !f.signIn.email)
|
|
1264
1306
|
throw new Error("mulguard: signIn.email action is required");
|
|
1265
1307
|
const S = async (c, ...u) => {
|
|
1266
1308
|
if (c)
|
|
@@ -1281,7 +1323,7 @@ function Zr(e) {
|
|
|
1281
1323
|
const u = await v.setSession(c.session);
|
|
1282
1324
|
return c.user && n.onSignIn && await S(n.onSignIn, c.user, c.session), u;
|
|
1283
1325
|
};
|
|
1284
|
-
if (Object.keys(s).length > 0 && !
|
|
1326
|
+
if (Object.keys(s).length > 0 && !f.oauthCallback) {
|
|
1285
1327
|
const c = sr(
|
|
1286
1328
|
{
|
|
1287
1329
|
oauthProviders: s,
|
|
@@ -1305,18 +1347,18 @@ function Zr(e) {
|
|
|
1305
1347
|
onError: n.onError
|
|
1306
1348
|
}
|
|
1307
1349
|
);
|
|
1308
|
-
|
|
1350
|
+
f.oauthCallback = c;
|
|
1309
1351
|
}
|
|
1310
1352
|
const h = tr(
|
|
1311
1353
|
{
|
|
1312
|
-
actions:
|
|
1354
|
+
actions: f,
|
|
1313
1355
|
callbacks: n,
|
|
1314
1356
|
saveSessionAfterAuth: y,
|
|
1315
1357
|
onError: n.onError
|
|
1316
1358
|
},
|
|
1317
1359
|
w
|
|
1318
|
-
),
|
|
1319
|
-
actions:
|
|
1360
|
+
), T = nr({
|
|
1361
|
+
actions: f,
|
|
1320
1362
|
callbacks: n,
|
|
1321
1363
|
saveSessionAfterAuth: y,
|
|
1322
1364
|
onError: n.onError
|
|
@@ -1354,9 +1396,9 @@ function Zr(e) {
|
|
|
1354
1396
|
* Sign up new user
|
|
1355
1397
|
*/
|
|
1356
1398
|
async signUp(c) {
|
|
1357
|
-
if (!
|
|
1399
|
+
if (!T)
|
|
1358
1400
|
throw new Error("Sign up is not configured. Provide signUp action in config.");
|
|
1359
|
-
return await
|
|
1401
|
+
return await T(c);
|
|
1360
1402
|
},
|
|
1361
1403
|
/**
|
|
1362
1404
|
* Sign out
|
|
@@ -1439,7 +1481,7 @@ function Zr(e) {
|
|
|
1439
1481
|
* ✅ Auto-generated if providers.oauth is configured in config
|
|
1440
1482
|
*/
|
|
1441
1483
|
async oauthCallback(c, u, d) {
|
|
1442
|
-
if (!
|
|
1484
|
+
if (!f.oauthCallback)
|
|
1443
1485
|
throw new Error(
|
|
1444
1486
|
"OAuth callback is not configured. Either provide oauthCallback action, or configure providers.oauth in config."
|
|
1445
1487
|
);
|
|
@@ -1451,7 +1493,7 @@ function Zr(e) {
|
|
|
1451
1493
|
};
|
|
1452
1494
|
let R = c;
|
|
1453
1495
|
if (!R) {
|
|
1454
|
-
const P = await Promise.resolve(
|
|
1496
|
+
const P = await Promise.resolve(l.get(d));
|
|
1455
1497
|
if (P && P.provider)
|
|
1456
1498
|
R = P.provider;
|
|
1457
1499
|
else
|
|
@@ -1468,7 +1510,7 @@ function Zr(e) {
|
|
|
1468
1510
|
errorCode: m.VALIDATION_ERROR
|
|
1469
1511
|
};
|
|
1470
1512
|
try {
|
|
1471
|
-
return await
|
|
1513
|
+
return await f.oauthCallback(R, u, d);
|
|
1472
1514
|
} catch (P) {
|
|
1473
1515
|
return n.onError && await S(n.onError, P instanceof Error ? P : new Error(String(P)), "oauthCallback"), {
|
|
1474
1516
|
success: !1,
|
|
@@ -1488,7 +1530,7 @@ function Zr(e) {
|
|
|
1488
1530
|
const d = await t.verify2FA(c);
|
|
1489
1531
|
if (d.success && d.session && !(u != null && u.skipCookieSave)) {
|
|
1490
1532
|
const R = await y(d);
|
|
1491
|
-
R.success || (process.env.NODE_ENV === "development" &&
|
|
1533
|
+
R.success || (process.env.NODE_ENV === "development" && I.debug("Failed to save session cookie after verify2FA", {
|
|
1492
1534
|
error: R.error,
|
|
1493
1535
|
warning: R.warning
|
|
1494
1536
|
}), n.onError && await S(
|
|
@@ -1569,7 +1611,7 @@ function Zr(e) {
|
|
|
1569
1611
|
const R = await u(c);
|
|
1570
1612
|
if (R.success && R.session) {
|
|
1571
1613
|
const C = await y(R);
|
|
1572
|
-
C.success || (process.env.NODE_ENV === "development" &&
|
|
1614
|
+
C.success || (process.env.NODE_ENV === "development" && I.debug("Failed to save session cookie after twoFactor.verify2FA", {
|
|
1573
1615
|
error: C.error,
|
|
1574
1616
|
warning: C.warning
|
|
1575
1617
|
}), n.onError && await S(
|
|
@@ -1625,7 +1667,7 @@ function Zr(e) {
|
|
|
1625
1667
|
}
|
|
1626
1668
|
return _;
|
|
1627
1669
|
}
|
|
1628
|
-
function
|
|
1670
|
+
function rt(e) {
|
|
1629
1671
|
return {
|
|
1630
1672
|
GET: async (r) => B(r, e, "GET"),
|
|
1631
1673
|
POST: async (r) => B(r, e, "POST")
|
|
@@ -1634,9 +1676,9 @@ function et(e) {
|
|
|
1634
1676
|
async function B(e, r, t) {
|
|
1635
1677
|
const n = new URL(e.url), s = or(n.pathname), i = s.split("/").filter(Boolean);
|
|
1636
1678
|
try {
|
|
1637
|
-
return t === "GET" ? await ar(e, r, s, i, n) : t === "POST" ? await cr(e, r, s, i, n) :
|
|
1679
|
+
return t === "GET" ? await ar(e, r, s, i, n) : t === "POST" ? await cr(e, r, s, i, n) : O("Method not allowed", 405);
|
|
1638
1680
|
} catch (o) {
|
|
1639
|
-
return
|
|
1681
|
+
return O(
|
|
1640
1682
|
o instanceof Error ? o.message : "Request failed",
|
|
1641
1683
|
500
|
|
1642
1684
|
);
|
|
@@ -1656,11 +1698,11 @@ async function ar(e, r, t, n, s) {
|
|
|
1656
1698
|
oauth: !!r.signIn.oauth,
|
|
1657
1699
|
passkey: !!r.signIn.passkey
|
|
1658
1700
|
}
|
|
1659
|
-
}) : re(t, n) ? await te(e, r, t, n, s, "GET") :
|
|
1701
|
+
}) : re(t, n) ? await te(e, r, t, n, s, "GET") : O("Not found", 404);
|
|
1660
1702
|
}
|
|
1661
1703
|
async function cr(e, r, t, n, s) {
|
|
1662
1704
|
const i = await ur(e);
|
|
1663
|
-
return t === "/sign-in" || n[0] === "sign-in" ? await fr(r, i) : t === "/sign-up" || n[0] === "sign-up" ? await dr(r, i) : t === "/sign-out" || n[0] === "sign-out" ? await hr(r) : t === "/reset-password" || n[0] === "reset-password" ? await gr(r, i) : t === "/verify-email" || n[0] === "verify-email" ? await wr(r, i) : t === "/refresh" || n[0] === "refresh" ? await pr(r) : re(t, n) ? await te(e, r, t, n, s, "POST", i) : t.startsWith("/passkey") ? await Er(r, t, n, i) : t === "/verify-2fa" || n[0] === "verify-2fa" ? await mr(r, i) : t.startsWith("/two-factor") ? await yr(r, n, i) :
|
|
1705
|
+
return t === "/sign-in" || n[0] === "sign-in" ? await fr(r, i) : t === "/sign-up" || n[0] === "sign-up" ? await dr(r, i) : t === "/sign-out" || n[0] === "sign-out" ? await hr(r) : t === "/reset-password" || n[0] === "reset-password" ? await gr(r, i) : t === "/verify-email" || n[0] === "verify-email" ? await wr(r, i) : t === "/refresh" || n[0] === "refresh" ? await pr(r) : re(t, n) ? await te(e, r, t, n, s, "POST", i) : t.startsWith("/passkey") ? await Er(r, t, n, i) : t === "/verify-2fa" || n[0] === "verify-2fa" ? await mr(r, i) : t.startsWith("/two-factor") ? await yr(r, n, i) : O("Not found", 404);
|
|
1664
1706
|
}
|
|
1665
1707
|
async function ur(e) {
|
|
1666
1708
|
try {
|
|
@@ -1674,15 +1716,15 @@ function re(e, r) {
|
|
|
1674
1716
|
}
|
|
1675
1717
|
async function te(e, r, t, n, s, i, o) {
|
|
1676
1718
|
if (!r.oauthCallback)
|
|
1677
|
-
return i === "GET" ?
|
|
1678
|
-
const a = lr(n, s, o),
|
|
1679
|
-
if (!
|
|
1680
|
-
return i === "GET" ?
|
|
1719
|
+
return i === "GET" ? V(e.url, "oauth_not_configured") : O("OAuth callback is not configured", 400);
|
|
1720
|
+
const a = lr(n, s, o), l = (o == null ? void 0 : o.code) ?? s.searchParams.get("code"), f = (o == null ? void 0 : o.state) ?? s.searchParams.get("state");
|
|
1721
|
+
if (!l || !f)
|
|
1722
|
+
return i === "GET" ? V(e.url, "oauth_missing_params") : O("Missing required OAuth parameters. Code and state are required.", 400);
|
|
1681
1723
|
try {
|
|
1682
|
-
const w = await r.oauthCallback(a ?? "",
|
|
1683
|
-
return i === "GET" ? w.success ? kr(e.url, s.searchParams.get("callbackUrl")) :
|
|
1724
|
+
const w = await r.oauthCallback(a ?? "", l, f);
|
|
1725
|
+
return i === "GET" ? w.success ? kr(e.url, s.searchParams.get("callbackUrl")) : V(e.url, w.error ?? "oauth_failed") : E.json(w);
|
|
1684
1726
|
} catch (w) {
|
|
1685
|
-
return i === "GET" ?
|
|
1727
|
+
return i === "GET" ? V(e.url, w instanceof Error ? w.message : "oauth_error") : O(w instanceof Error ? w.message : "OAuth callback failed", 500);
|
|
1686
1728
|
}
|
|
1687
1729
|
}
|
|
1688
1730
|
function lr(e, r, t) {
|
|
@@ -1698,21 +1740,21 @@ async function fr(e, r) {
|
|
|
1698
1740
|
}
|
|
1699
1741
|
if (r.provider === "oauth" && r.providerName) {
|
|
1700
1742
|
if (!e.signIn.oauth)
|
|
1701
|
-
return
|
|
1743
|
+
return O("OAuth is not configured", 400);
|
|
1702
1744
|
const t = await e.signIn.oauth(r.providerName);
|
|
1703
1745
|
return E.json(t);
|
|
1704
1746
|
}
|
|
1705
1747
|
if (r.provider === "passkey") {
|
|
1706
1748
|
if (!e.signIn.passkey)
|
|
1707
|
-
return
|
|
1749
|
+
return O("PassKey is not configured", 400);
|
|
1708
1750
|
const t = await e.signIn.passkey(r.options);
|
|
1709
1751
|
return E.json(t);
|
|
1710
1752
|
}
|
|
1711
|
-
return
|
|
1753
|
+
return O("Invalid sign in request", 400);
|
|
1712
1754
|
}
|
|
1713
1755
|
async function dr(e, r) {
|
|
1714
1756
|
if (!e.signUp)
|
|
1715
|
-
return
|
|
1757
|
+
return O("Sign up is not configured", 400);
|
|
1716
1758
|
const t = await e.signUp(r);
|
|
1717
1759
|
return E.json(t);
|
|
1718
1760
|
}
|
|
@@ -1722,17 +1764,17 @@ async function hr(e) {
|
|
|
1722
1764
|
}
|
|
1723
1765
|
async function gr(e, r) {
|
|
1724
1766
|
if (!e.resetPassword)
|
|
1725
|
-
return
|
|
1767
|
+
return O("Password reset is not configured", 400);
|
|
1726
1768
|
if (!r.email || typeof r.email != "string")
|
|
1727
|
-
return
|
|
1769
|
+
return O("Email is required", 400);
|
|
1728
1770
|
const t = await e.resetPassword(r.email);
|
|
1729
1771
|
return E.json(t);
|
|
1730
1772
|
}
|
|
1731
1773
|
async function wr(e, r) {
|
|
1732
1774
|
if (!e.verifyEmail)
|
|
1733
|
-
return
|
|
1775
|
+
return O("Email verification is not configured", 400);
|
|
1734
1776
|
if (!r.token || typeof r.token != "string")
|
|
1735
|
-
return
|
|
1777
|
+
return O("Token is required", 400);
|
|
1736
1778
|
const t = await e.verifyEmail(r.token);
|
|
1737
1779
|
return E.json(t);
|
|
1738
1780
|
}
|
|
@@ -1746,9 +1788,9 @@ async function pr(e) {
|
|
|
1746
1788
|
}
|
|
1747
1789
|
async function mr(e, r) {
|
|
1748
1790
|
if (!e.verify2FA)
|
|
1749
|
-
return
|
|
1791
|
+
return O("2FA verification is not configured", 400);
|
|
1750
1792
|
if (!r.email || !r.userId || !r.code)
|
|
1751
|
-
return
|
|
1793
|
+
return O("Missing required parameters. Email, userId, and code are required.", 400);
|
|
1752
1794
|
const t = {
|
|
1753
1795
|
email: r.email,
|
|
1754
1796
|
userId: r.userId,
|
|
@@ -1758,7 +1800,7 @@ async function mr(e, r) {
|
|
|
1758
1800
|
}
|
|
1759
1801
|
async function Er(e, r, t, n) {
|
|
1760
1802
|
if (!e.passkey)
|
|
1761
|
-
return
|
|
1803
|
+
return O("PassKey is not configured", 400);
|
|
1762
1804
|
const s = t[1];
|
|
1763
1805
|
if (s === "register" && e.passkey.register) {
|
|
1764
1806
|
const i = await e.passkey.register(n.options);
|
|
@@ -1770,15 +1812,15 @@ async function Er(e, r, t, n) {
|
|
|
1770
1812
|
}
|
|
1771
1813
|
if (s === "remove" && e.passkey.remove) {
|
|
1772
1814
|
if (!n.passkeyId || typeof n.passkeyId != "string")
|
|
1773
|
-
return
|
|
1815
|
+
return O("Passkey ID is required", 400);
|
|
1774
1816
|
const i = await e.passkey.remove(n.passkeyId);
|
|
1775
1817
|
return E.json(i);
|
|
1776
1818
|
}
|
|
1777
|
-
return
|
|
1819
|
+
return O("Invalid Passkey request", 400);
|
|
1778
1820
|
}
|
|
1779
1821
|
async function yr(e, r, t) {
|
|
1780
1822
|
if (!e.twoFactor)
|
|
1781
|
-
return
|
|
1823
|
+
return O("Two-Factor Authentication is not configured", 400);
|
|
1782
1824
|
const n = r[1];
|
|
1783
1825
|
if (n === "enable" && e.twoFactor.enable) {
|
|
1784
1826
|
const s = await e.twoFactor.enable();
|
|
@@ -1786,7 +1828,7 @@ async function yr(e, r, t) {
|
|
|
1786
1828
|
}
|
|
1787
1829
|
if (n === "verify" && e.twoFactor.verify) {
|
|
1788
1830
|
if (!t.code || typeof t.code != "string")
|
|
1789
|
-
return
|
|
1831
|
+
return O("Code is required", 400);
|
|
1790
1832
|
const s = await e.twoFactor.verify(t.code);
|
|
1791
1833
|
return E.json(s);
|
|
1792
1834
|
}
|
|
@@ -1802,9 +1844,9 @@ async function yr(e, r, t) {
|
|
|
1802
1844
|
const s = await e.twoFactor.isEnabled();
|
|
1803
1845
|
return E.json({ enabled: s });
|
|
1804
1846
|
}
|
|
1805
|
-
return
|
|
1847
|
+
return O("Invalid two-factor request", 400);
|
|
1806
1848
|
}
|
|
1807
|
-
function
|
|
1849
|
+
function O(e, r) {
|
|
1808
1850
|
return E.json(
|
|
1809
1851
|
{
|
|
1810
1852
|
success: !1,
|
|
@@ -1813,14 +1855,14 @@ function T(e, r) {
|
|
|
1813
1855
|
{ status: r }
|
|
1814
1856
|
);
|
|
1815
1857
|
}
|
|
1816
|
-
function
|
|
1858
|
+
function V(e, r) {
|
|
1817
1859
|
return E.redirect(new URL(`/login?error=${encodeURIComponent(r)}`, e));
|
|
1818
1860
|
}
|
|
1819
1861
|
function kr(e, r) {
|
|
1820
1862
|
const t = r ?? "/";
|
|
1821
1863
|
return E.redirect(new URL(t, e));
|
|
1822
1864
|
}
|
|
1823
|
-
function
|
|
1865
|
+
function tt(e) {
|
|
1824
1866
|
return async (r) => {
|
|
1825
1867
|
const { method: t, nextUrl: n } = r, i = n.pathname.replace(/^\/api\/auth/, "") || "/";
|
|
1826
1868
|
try {
|
|
@@ -1830,7 +1872,7 @@ function rt(e) {
|
|
|
1830
1872
|
o = await r.json();
|
|
1831
1873
|
} catch {
|
|
1832
1874
|
}
|
|
1833
|
-
const a = Object.fromEntries(n.searchParams.entries()),
|
|
1875
|
+
const a = Object.fromEntries(n.searchParams.entries()), l = await fetch(
|
|
1834
1876
|
`${process.env.NEXT_PUBLIC_API_URL || ""}/api/auth${i}${Object.keys(a).length > 0 ? `?${new URLSearchParams(a).toString()}` : ""}`,
|
|
1835
1877
|
{
|
|
1836
1878
|
method: t,
|
|
@@ -1840,11 +1882,11 @@ function rt(e) {
|
|
|
1840
1882
|
},
|
|
1841
1883
|
body: o ? JSON.stringify(o) : void 0
|
|
1842
1884
|
}
|
|
1843
|
-
),
|
|
1844
|
-
return E.json(
|
|
1845
|
-
status:
|
|
1885
|
+
), f = await l.json();
|
|
1886
|
+
return E.json(f, {
|
|
1887
|
+
status: l.status,
|
|
1846
1888
|
headers: {
|
|
1847
|
-
...Object.fromEntries(
|
|
1889
|
+
...Object.fromEntries(l.headers.entries())
|
|
1848
1890
|
}
|
|
1849
1891
|
});
|
|
1850
1892
|
} catch (o) {
|
|
@@ -1858,7 +1900,7 @@ function rt(e) {
|
|
|
1858
1900
|
}
|
|
1859
1901
|
};
|
|
1860
1902
|
}
|
|
1861
|
-
function
|
|
1903
|
+
function nt(e) {
|
|
1862
1904
|
return async (r) => {
|
|
1863
1905
|
const { searchParams: t } = r.nextUrl, n = t.get("provider"), s = t.get("code"), i = t.get("state");
|
|
1864
1906
|
if (!n || !s || !i)
|
|
@@ -1900,13 +1942,13 @@ function F(e, r) {
|
|
|
1900
1942
|
s && typeof s == "string" && r.headers.set(n, s);
|
|
1901
1943
|
return r;
|
|
1902
1944
|
}
|
|
1903
|
-
function
|
|
1945
|
+
function st() {
|
|
1904
1946
|
return async (e) => {
|
|
1905
1947
|
const r = E.next();
|
|
1906
1948
|
return F(e, r);
|
|
1907
1949
|
};
|
|
1908
1950
|
}
|
|
1909
|
-
function
|
|
1951
|
+
function it(e, r = {}) {
|
|
1910
1952
|
const {
|
|
1911
1953
|
protectedRoutes: t = [],
|
|
1912
1954
|
publicRoutes: n = [],
|
|
@@ -1914,18 +1956,18 @@ function st(e, r = {}) {
|
|
|
1914
1956
|
redirectIfAuthenticated: i
|
|
1915
1957
|
} = r;
|
|
1916
1958
|
return async (o) => {
|
|
1917
|
-
const { pathname: a } = o.nextUrl,
|
|
1918
|
-
let
|
|
1959
|
+
const { pathname: a } = o.nextUrl, l = t.some((g) => a.startsWith(g));
|
|
1960
|
+
let f = null;
|
|
1919
1961
|
try {
|
|
1920
|
-
|
|
1962
|
+
f = await e.getSession();
|
|
1921
1963
|
} catch (g) {
|
|
1922
1964
|
console.error("Middleware: Failed to get session:", g);
|
|
1923
1965
|
}
|
|
1924
|
-
if (
|
|
1966
|
+
if (l && !f) {
|
|
1925
1967
|
const g = o.nextUrl.clone();
|
|
1926
1968
|
return g.pathname = s, g.searchParams.set("callbackUrl", a), E.redirect(g);
|
|
1927
1969
|
}
|
|
1928
|
-
if (i &&
|
|
1970
|
+
if (i && f && (a.startsWith("/login") || a.startsWith("/register"))) {
|
|
1929
1971
|
const A = o.nextUrl.clone();
|
|
1930
1972
|
A.pathname = i;
|
|
1931
1973
|
const S = E.redirect(A);
|
|
@@ -1935,7 +1977,7 @@ function st(e, r = {}) {
|
|
|
1935
1977
|
return F(o, w);
|
|
1936
1978
|
};
|
|
1937
1979
|
}
|
|
1938
|
-
async function
|
|
1980
|
+
async function ot(e, r) {
|
|
1939
1981
|
var t;
|
|
1940
1982
|
try {
|
|
1941
1983
|
const n = await e.getSession();
|
|
@@ -1944,7 +1986,7 @@ async function it(e, r) {
|
|
|
1944
1986
|
return !1;
|
|
1945
1987
|
}
|
|
1946
1988
|
}
|
|
1947
|
-
function
|
|
1989
|
+
function at(e) {
|
|
1948
1990
|
const {
|
|
1949
1991
|
auth: r,
|
|
1950
1992
|
protectedRoutes: t = [],
|
|
@@ -1954,26 +1996,26 @@ function ot(e) {
|
|
|
1954
1996
|
apiPrefix: o = "/api/auth"
|
|
1955
1997
|
} = e;
|
|
1956
1998
|
return async (a) => {
|
|
1957
|
-
const { pathname:
|
|
1958
|
-
if (
|
|
1999
|
+
const { pathname: l } = a.nextUrl;
|
|
2000
|
+
if (l.startsWith(o)) {
|
|
1959
2001
|
const A = E.next();
|
|
1960
2002
|
return F(a, A);
|
|
1961
2003
|
}
|
|
1962
|
-
const
|
|
2004
|
+
const f = t.some((A) => l.startsWith(A));
|
|
1963
2005
|
let w = null;
|
|
1964
|
-
if (
|
|
2006
|
+
if (f || i)
|
|
1965
2007
|
try {
|
|
1966
2008
|
w = await r.getSession();
|
|
1967
2009
|
} catch (A) {
|
|
1968
2010
|
console.error("Middleware: Failed to get session:", A);
|
|
1969
2011
|
}
|
|
1970
|
-
if (
|
|
2012
|
+
if (f && !w) {
|
|
1971
2013
|
const A = a.nextUrl.clone();
|
|
1972
|
-
A.pathname = s, A.searchParams.set("callbackUrl",
|
|
2014
|
+
A.pathname = s, A.searchParams.set("callbackUrl", l);
|
|
1973
2015
|
const S = E.redirect(A);
|
|
1974
2016
|
return F(a, S);
|
|
1975
2017
|
}
|
|
1976
|
-
if (i && w && (
|
|
2018
|
+
if (i && w && (l.startsWith("/login") || l.startsWith("/register"))) {
|
|
1977
2019
|
const S = a.nextUrl.clone();
|
|
1978
2020
|
S.pathname = i;
|
|
1979
2021
|
const v = E.redirect(S);
|
|
@@ -1983,7 +2025,7 @@ function ot(e) {
|
|
|
1983
2025
|
return F(a, g);
|
|
1984
2026
|
};
|
|
1985
2027
|
}
|
|
1986
|
-
async function
|
|
2028
|
+
async function ct(e, r) {
|
|
1987
2029
|
var t;
|
|
1988
2030
|
try {
|
|
1989
2031
|
const n = await e.getSession();
|
|
@@ -1993,52 +2035,53 @@ async function at(e, r) {
|
|
|
1993
2035
|
}
|
|
1994
2036
|
}
|
|
1995
2037
|
export {
|
|
1996
|
-
|
|
2038
|
+
Te as CSRFProtection,
|
|
1997
2039
|
fe as DEFAULT_SECURITY_HEADERS,
|
|
1998
|
-
|
|
2040
|
+
Oe as MemoryCSRFStore,
|
|
1999
2041
|
ze as MemoryOAuthStateStore,
|
|
2000
2042
|
le as RateLimiter,
|
|
2001
|
-
|
|
2043
|
+
Tr as applySecurityHeaders,
|
|
2002
2044
|
oe as buildCookieOptions,
|
|
2003
2045
|
be as buildOAuthAuthorizationUrl,
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2046
|
+
ot as checkRole,
|
|
2047
|
+
ct as checkRoleProxy,
|
|
2048
|
+
Vr as containsXSSPattern,
|
|
2049
|
+
tt as createApiHandler,
|
|
2050
|
+
it as createAuthMiddleware,
|
|
2009
2051
|
Dr as createCSRFProtection,
|
|
2010
2052
|
$e as createMemoryOAuthStateStore,
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
pt as
|
|
2017
|
-
mt as
|
|
2018
|
-
Et as
|
|
2053
|
+
nt as createOAuthCallbackHandler,
|
|
2054
|
+
at as createProxyMiddleware,
|
|
2055
|
+
Or as createRateLimiter,
|
|
2056
|
+
Zr as createRedisOAuthStateStore,
|
|
2057
|
+
st as createSecurityMiddleware,
|
|
2058
|
+
pt as createServerAuthMiddleware,
|
|
2059
|
+
mt as createServerHelpers,
|
|
2060
|
+
Et as createServerUtils,
|
|
2061
|
+
yt as createSessionManager,
|
|
2019
2062
|
ie as deleteCookie,
|
|
2020
|
-
|
|
2021
|
-
|
|
2063
|
+
kt as deleteOAuthStateCookie,
|
|
2064
|
+
Ie as escapeHTML,
|
|
2022
2065
|
Ue as exchangeOAuthCode,
|
|
2023
2066
|
_e as generateCSRFToken,
|
|
2024
2067
|
Y as generateToken,
|
|
2025
2068
|
ce as getCookie,
|
|
2026
|
-
|
|
2069
|
+
vt as getCurrentUser,
|
|
2027
2070
|
Br as getErrorCode,
|
|
2028
2071
|
qr as getErrorMessage,
|
|
2029
|
-
|
|
2072
|
+
St as getOAuthStateCookie,
|
|
2030
2073
|
Fe as getOAuthUserInfo,
|
|
2031
2074
|
j as getProviderMetadata,
|
|
2032
2075
|
H as getSecurityHeaders,
|
|
2033
|
-
|
|
2034
|
-
|
|
2076
|
+
Rt as getServerSession,
|
|
2077
|
+
At as getSessionTimeUntilExpiry,
|
|
2035
2078
|
Xr as getUserFriendlyError,
|
|
2036
2079
|
Gr as hasErrorCode,
|
|
2037
2080
|
Ce as isAuthError,
|
|
2038
2081
|
Hr as isAuthSuccess,
|
|
2039
2082
|
Qr as isOAuthProviderConfig,
|
|
2040
2083
|
Kr as isRetryableError,
|
|
2041
|
-
|
|
2084
|
+
Ot as isSessionExpiredNullable,
|
|
2042
2085
|
Tt as isSessionExpiringSoon,
|
|
2043
2086
|
It as isSessionValid,
|
|
2044
2087
|
Yr as isSupportedProvider,
|
|
@@ -2050,30 +2093,30 @@ export {
|
|
|
2050
2093
|
_r as isValidPassword,
|
|
2051
2094
|
Fr as isValidToken,
|
|
2052
2095
|
Ur as isValidURL,
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2096
|
+
et as mulguard,
|
|
2097
|
+
_t as refreshSession,
|
|
2098
|
+
Pt as requireAuth,
|
|
2099
|
+
Ct as requireRole,
|
|
2100
|
+
bt as requireServerAuthMiddleware,
|
|
2101
|
+
Ut as requireServerRoleMiddleware,
|
|
2059
2102
|
Lr as sanitizeHTML,
|
|
2060
2103
|
zr as sanitizeInput,
|
|
2061
|
-
|
|
2104
|
+
Mr as sanitizeUserInput,
|
|
2062
2105
|
ae as setCookie,
|
|
2063
2106
|
Jr as signIn,
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2107
|
+
ft as signInEmailAction,
|
|
2108
|
+
dt as signOutAction,
|
|
2109
|
+
ht as signUpAction,
|
|
2110
|
+
Nt as storeOAuthStateCookie,
|
|
2111
|
+
rt as toNextJsHandler,
|
|
2069
2112
|
G as validateAndSanitizeEmail,
|
|
2070
2113
|
X as validateAndSanitizeInput,
|
|
2071
2114
|
Pr as validateAndSanitizeName,
|
|
2072
|
-
|
|
2115
|
+
Ir as validateAndSanitizePassword,
|
|
2073
2116
|
Q as validateCSRFToken,
|
|
2074
2117
|
N as validateSessionStructure,
|
|
2075
2118
|
Nr as validateToken,
|
|
2076
2119
|
br as validateURL,
|
|
2077
|
-
|
|
2120
|
+
gt as verify2FAAction,
|
|
2078
2121
|
F as withSecurityHeaders
|
|
2079
2122
|
};
|