mulguard 1.1.5 → 1.1.6
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/index/index.js +1 -1
- package/dist/index/index.mjs +178 -171
- package/dist/{oauth-state-LE-qeq-K.mjs → oauth-state-DKle8eCr.mjs} +111 -104
- package/dist/oauth-state-DlvrCV11.js +1 -0
- package/dist/server/index.js +1 -1
- package/dist/server/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/oauth-state-CzIWQq3s.js +0 -1
package/dist/index/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ var se = (e, r, t) => r in e ? ne(e, r, { enumerable: !0, configurable: !0, writ
|
|
|
3
3
|
var b = (e, r, t) => se(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
4
|
import { A as m, d as oe, e as ie, c as ae, g as ce } from "../actions-DeCfLtHA.mjs";
|
|
5
5
|
import { a as wt, s as pt, b as mt, v as Et } from "../actions-DeCfLtHA.mjs";
|
|
6
|
-
import { v as U } from "../oauth-state-
|
|
7
|
-
import { c as kt, p as vt, k as St, n as At, m as Rt, j as Ot, l as Tt, e as It, g as _t, b as Pt, i as Ct, a as Nt, o as bt, f as Ut, h as Ft, r as xt, d as Dt, s as Lt } from "../oauth-state-
|
|
6
|
+
import { v as U } from "../oauth-state-DKle8eCr.mjs";
|
|
7
|
+
import { c as kt, p as vt, k as St, n as At, m as Rt, j as Ot, l as Tt, e as It, g as _t, b as Pt, i as Ct, a as Nt, o as bt, f as Ut, h as Ft, r as xt, d as Dt, s as Lt } from "../oauth-state-DKle8eCr.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) */
|
|
@@ -413,11 +413,11 @@ function Ne(e, r, t, n) {
|
|
|
413
413
|
state: n
|
|
414
414
|
});
|
|
415
415
|
if (s.defaultParams)
|
|
416
|
-
for (const [u,
|
|
417
|
-
a.append(u,
|
|
416
|
+
for (const [u, f] of Object.entries(s.defaultParams))
|
|
417
|
+
a.append(u, f);
|
|
418
418
|
if (r.params)
|
|
419
|
-
for (const [u,
|
|
420
|
-
a.set(u,
|
|
419
|
+
for (const [u, f] of Object.entries(r.params))
|
|
420
|
+
a.set(u, f);
|
|
421
421
|
return `${s.authorizationUrl}?${a.toString()}`;
|
|
422
422
|
}
|
|
423
423
|
async function be(e, r, t, n) {
|
|
@@ -446,13 +446,13 @@ async function be(e, r, t, n) {
|
|
|
446
446
|
});
|
|
447
447
|
if (!i.ok) {
|
|
448
448
|
const u = await i.text();
|
|
449
|
-
let
|
|
449
|
+
let f = `Failed to exchange code for tokens: ${u}`;
|
|
450
450
|
try {
|
|
451
451
|
const g = JSON.parse(u);
|
|
452
|
-
|
|
452
|
+
f = g.error_description ?? g.error ?? f;
|
|
453
453
|
} catch {
|
|
454
454
|
}
|
|
455
|
-
throw new Error(
|
|
455
|
+
throw new Error(f);
|
|
456
456
|
}
|
|
457
457
|
const a = await i.json();
|
|
458
458
|
if (!Ue(a))
|
|
@@ -588,22 +588,22 @@ function We(e) {
|
|
|
588
588
|
path: "/"
|
|
589
589
|
});
|
|
590
590
|
return {
|
|
591
|
-
async set(u,
|
|
591
|
+
async set(u, f, g) {
|
|
592
592
|
const w = JSON.stringify({
|
|
593
593
|
state: u,
|
|
594
|
-
provider:
|
|
595
|
-
expiresAt:
|
|
594
|
+
provider: f.provider,
|
|
595
|
+
expiresAt: f.expiresAt
|
|
596
596
|
});
|
|
597
597
|
await Promise.resolve(
|
|
598
598
|
i.setCookie(r, w, a(t))
|
|
599
599
|
);
|
|
600
600
|
},
|
|
601
601
|
async get(u) {
|
|
602
|
-
const
|
|
603
|
-
if (!
|
|
602
|
+
const f = await Promise.resolve(i.getCookie(r));
|
|
603
|
+
if (!f)
|
|
604
604
|
return null;
|
|
605
605
|
try {
|
|
606
|
-
const g = JSON.parse(
|
|
606
|
+
const g = JSON.parse(f);
|
|
607
607
|
return g.state !== u ? null : g.expiresAt < Date.now() ? (await Promise.resolve(
|
|
608
608
|
i.deleteCookie(r, { path: "/" })
|
|
609
609
|
), null) : {
|
|
@@ -741,12 +741,12 @@ function Ge(e = {}) {
|
|
|
741
741
|
level: t = He,
|
|
742
742
|
context: n,
|
|
743
743
|
formatter: s = Ke
|
|
744
|
-
} = e, o = (a) => r && a >= t, i = (a, u,
|
|
744
|
+
} = e, o = (a) => r && a >= t, i = (a, u, f, g) => ({
|
|
745
745
|
level: a,
|
|
746
746
|
message: u,
|
|
747
747
|
timestamp: /* @__PURE__ */ new Date(),
|
|
748
748
|
context: n,
|
|
749
|
-
data:
|
|
749
|
+
data: f ? Xe(f) : void 0,
|
|
750
750
|
error: g
|
|
751
751
|
});
|
|
752
752
|
return {
|
|
@@ -755,8 +755,8 @@ function Ge(e = {}) {
|
|
|
755
755
|
0
|
|
756
756
|
/* DEBUG */
|
|
757
757
|
)) {
|
|
758
|
-
const
|
|
759
|
-
console.debug(s(
|
|
758
|
+
const f = i(0, a, u);
|
|
759
|
+
console.debug(s(f));
|
|
760
760
|
}
|
|
761
761
|
},
|
|
762
762
|
info: (a, u) => {
|
|
@@ -764,8 +764,8 @@ function Ge(e = {}) {
|
|
|
764
764
|
1
|
|
765
765
|
/* INFO */
|
|
766
766
|
)) {
|
|
767
|
-
const
|
|
768
|
-
console.info(s(
|
|
767
|
+
const f = i(1, a, u);
|
|
768
|
+
console.info(s(f));
|
|
769
769
|
}
|
|
770
770
|
},
|
|
771
771
|
warn: (a, u) => {
|
|
@@ -773,8 +773,8 @@ function Ge(e = {}) {
|
|
|
773
773
|
2
|
|
774
774
|
/* WARN */
|
|
775
775
|
)) {
|
|
776
|
-
const
|
|
777
|
-
console.warn(s(
|
|
776
|
+
const f = i(2, a, u);
|
|
777
|
+
console.warn(s(f));
|
|
778
778
|
}
|
|
779
779
|
},
|
|
780
780
|
error: (a, u) => {
|
|
@@ -782,8 +782,8 @@ function Ge(e = {}) {
|
|
|
782
782
|
3
|
|
783
783
|
/* ERROR */
|
|
784
784
|
)) {
|
|
785
|
-
const
|
|
786
|
-
console.error(s(w)),
|
|
785
|
+
const f = u instanceof Error ? u : void 0, g = u instanceof Error ? void 0 : u, w = i(3, a, g, f);
|
|
786
|
+
console.error(s(w)), f && console.error(f);
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
};
|
|
@@ -816,11 +816,11 @@ function Je(e, r, t, n = {}) {
|
|
|
816
816
|
retryDelay: i = 1e3,
|
|
817
817
|
rateLimit: a = 3,
|
|
818
818
|
autoSignOutOnFailure: u = !0,
|
|
819
|
-
redirectToLogin:
|
|
819
|
+
redirectToLogin: f = "/login",
|
|
820
820
|
autoRedirectOnFailure: g = !0
|
|
821
821
|
} = n;
|
|
822
822
|
let w = null, R = !1;
|
|
823
|
-
const
|
|
823
|
+
const A = [], S = [], y = 60 * 1e3;
|
|
824
824
|
let h = 0, T = !1, _ = null;
|
|
825
825
|
const L = 2, M = 60 * 1e3;
|
|
826
826
|
function c() {
|
|
@@ -830,22 +830,22 @@ function Je(e, r, t, n = {}) {
|
|
|
830
830
|
return !1;
|
|
831
831
|
T = !1, _ = null, h = 0;
|
|
832
832
|
}
|
|
833
|
-
for (;
|
|
834
|
-
const p =
|
|
833
|
+
for (; S.length > 0; ) {
|
|
834
|
+
const p = S[0];
|
|
835
835
|
if (p !== void 0 && p < k - y)
|
|
836
|
-
|
|
836
|
+
S.shift();
|
|
837
837
|
else
|
|
838
838
|
break;
|
|
839
839
|
}
|
|
840
|
-
return
|
|
840
|
+
return S.length >= a ? !1 : (S.push(k), !0);
|
|
841
841
|
}
|
|
842
|
-
function
|
|
842
|
+
function l() {
|
|
843
843
|
h++, h >= L && (T = !0, _ = Date.now() + M, process.env.NODE_ENV === "development" && console.warn("[TokenRefreshManager] Circuit breaker opened - too many consecutive failures"));
|
|
844
844
|
}
|
|
845
845
|
function d() {
|
|
846
846
|
h = 0, T = !1, _ = null;
|
|
847
847
|
}
|
|
848
|
-
async function
|
|
848
|
+
async function v(k = 1) {
|
|
849
849
|
if (!s)
|
|
850
850
|
return null;
|
|
851
851
|
if (!c())
|
|
@@ -854,12 +854,12 @@ function Je(e, r, t, n = {}) {
|
|
|
854
854
|
const p = await e();
|
|
855
855
|
if (p)
|
|
856
856
|
return d(), P(p), n.onTokenRefreshed && await Promise.resolve(n.onTokenRefreshed(p)), p;
|
|
857
|
-
if (
|
|
858
|
-
return await $(i * k),
|
|
857
|
+
if (l(), k < o)
|
|
858
|
+
return await $(i * k), v(k + 1);
|
|
859
859
|
throw new Error("Token refresh failed: refresh function returned null");
|
|
860
860
|
} catch (p) {
|
|
861
|
-
if (
|
|
862
|
-
return await $(i * k),
|
|
861
|
+
if (l(), k < o && C(p))
|
|
862
|
+
return await $(i * k), v(k + 1);
|
|
863
863
|
throw p;
|
|
864
864
|
}
|
|
865
865
|
}
|
|
@@ -874,14 +874,14 @@ function Je(e, r, t, n = {}) {
|
|
|
874
874
|
return !1;
|
|
875
875
|
}
|
|
876
876
|
function P(k) {
|
|
877
|
-
const p = [...
|
|
878
|
-
|
|
877
|
+
const p = [...A];
|
|
878
|
+
A.length = 0;
|
|
879
879
|
for (const { resolve: N } of p)
|
|
880
880
|
N(k);
|
|
881
881
|
}
|
|
882
882
|
function z(k) {
|
|
883
|
-
const p = [...
|
|
884
|
-
|
|
883
|
+
const p = [...A];
|
|
884
|
+
A.length = 0;
|
|
885
885
|
for (const { reject: N } of p)
|
|
886
886
|
N(k);
|
|
887
887
|
}
|
|
@@ -893,7 +893,7 @@ function Je(e, r, t, n = {}) {
|
|
|
893
893
|
if (n.onTokenRefreshFailed && await Promise.resolve(n.onTokenRefreshFailed(k)), u && (await t(), await r(), g && typeof window < "u")) {
|
|
894
894
|
let p = !0;
|
|
895
895
|
if (n.onBeforeRedirect && (p = await Promise.resolve(n.onBeforeRedirect(k))), p) {
|
|
896
|
-
const N = new URL(
|
|
896
|
+
const N = new URL(f, window.location.origin);
|
|
897
897
|
N.searchParams.set("reason", "session_expired"), N.searchParams.set("redirect", window.location.pathname + window.location.search), window.location.href = N.toString();
|
|
898
898
|
}
|
|
899
899
|
}
|
|
@@ -906,7 +906,7 @@ function Je(e, r, t, n = {}) {
|
|
|
906
906
|
* Refresh token with single refresh queue
|
|
907
907
|
*/
|
|
908
908
|
async refreshToken() {
|
|
909
|
-
return s ? w || (R = !0, w =
|
|
909
|
+
return s ? w || (R = !0, w = v().then((k) => (R = !1, w = null, k)).catch((k) => {
|
|
910
910
|
throw R = !1, w = null, z(k), W(k).catch(() => {
|
|
911
911
|
}), k;
|
|
912
912
|
}), w) : null;
|
|
@@ -922,14 +922,14 @@ function Je(e, r, t, n = {}) {
|
|
|
922
922
|
*/
|
|
923
923
|
async waitForRefresh() {
|
|
924
924
|
return w ? new Promise((k, p) => {
|
|
925
|
-
|
|
925
|
+
A.push({ resolve: k, reject: p });
|
|
926
926
|
}) : null;
|
|
927
927
|
},
|
|
928
928
|
/**
|
|
929
929
|
* Clear state
|
|
930
930
|
*/
|
|
931
931
|
clear() {
|
|
932
|
-
w = null, R = !1,
|
|
932
|
+
w = null, R = !1, S.length = 0, d(), z(new Error("Token refresh manager cleared"));
|
|
933
933
|
},
|
|
934
934
|
/**
|
|
935
935
|
* Handle token refresh failure
|
|
@@ -1005,7 +1005,7 @@ function er(e) {
|
|
|
1005
1005
|
));
|
|
1006
1006
|
}
|
|
1007
1007
|
return null;
|
|
1008
|
-
},
|
|
1008
|
+
}, f = async (y) => {
|
|
1009
1009
|
if (!U(y))
|
|
1010
1010
|
return {
|
|
1011
1011
|
success: !1,
|
|
@@ -1036,7 +1036,7 @@ function er(e) {
|
|
|
1036
1036
|
};
|
|
1037
1037
|
return {
|
|
1038
1038
|
getSession: u,
|
|
1039
|
-
setSession:
|
|
1039
|
+
setSession: f,
|
|
1040
1040
|
clearSessionCookie: g,
|
|
1041
1041
|
getAccessToken: w,
|
|
1042
1042
|
getRefreshToken: async () => {
|
|
@@ -1209,7 +1209,7 @@ function sr(e) {
|
|
|
1209
1209
|
}
|
|
1210
1210
|
function or(e, r) {
|
|
1211
1211
|
const t = rr(e), n = tr(e, r), s = nr(e), o = sr(e);
|
|
1212
|
-
return Object.assign(async (u,
|
|
1212
|
+
return Object.assign(async (u, f) => {
|
|
1213
1213
|
if (!u || typeof u != "string")
|
|
1214
1214
|
throw new Error("Provider is required");
|
|
1215
1215
|
const g = X(u, {
|
|
@@ -1223,22 +1223,22 @@ function or(e, r) {
|
|
|
1223
1223
|
if (w === "google" || w === "github" || w === "apple" || w === "facebook" || typeof w == "string" && !["credentials", "otp", "passkey"].includes(w))
|
|
1224
1224
|
return n(w);
|
|
1225
1225
|
if (w === "credentials")
|
|
1226
|
-
return !
|
|
1226
|
+
return !f || !("email" in f) || !("password" in f) ? {
|
|
1227
1227
|
success: !1,
|
|
1228
1228
|
error: "Credentials are required",
|
|
1229
1229
|
errorCode: m.VALIDATION_ERROR
|
|
1230
|
-
} : t(
|
|
1230
|
+
} : t(f);
|
|
1231
1231
|
if (w === "otp") {
|
|
1232
|
-
if (!
|
|
1232
|
+
if (!f || !("email" in f))
|
|
1233
1233
|
return {
|
|
1234
1234
|
success: !1,
|
|
1235
1235
|
error: "Email is required",
|
|
1236
1236
|
errorCode: m.VALIDATION_ERROR
|
|
1237
1237
|
};
|
|
1238
|
-
const R =
|
|
1238
|
+
const R = f;
|
|
1239
1239
|
return s(R.email, R.code);
|
|
1240
1240
|
}
|
|
1241
|
-
return w === "passkey" ? o(
|
|
1241
|
+
return w === "passkey" ? o(f) : {
|
|
1242
1242
|
success: !1,
|
|
1243
1243
|
error: "Invalid provider",
|
|
1244
1244
|
errorCode: m.VALIDATION_ERROR
|
|
@@ -1282,7 +1282,7 @@ function ar(e, r) {
|
|
|
1282
1282
|
errorCode: m.VALIDATION_ERROR
|
|
1283
1283
|
};
|
|
1284
1284
|
try {
|
|
1285
|
-
const i = o.redirectUri ?? `${e.baseUrl}/api/auth/callback/${t}`, a = await be(t, o, n, i), u = await Fe(t, a.access_token),
|
|
1285
|
+
const i = o.redirectUri ?? `${e.baseUrl}/api/auth/callback/${t}`, a = await be(t, o, n, i), u = await Fe(t, a.access_token), f = {
|
|
1286
1286
|
id: u.id,
|
|
1287
1287
|
email: u.email,
|
|
1288
1288
|
name: u.name,
|
|
@@ -1303,7 +1303,7 @@ function ar(e, r) {
|
|
|
1303
1303
|
if (e.callbacks.onOAuthUser) {
|
|
1304
1304
|
const g = await q(
|
|
1305
1305
|
e.callbacks.onOAuthUser,
|
|
1306
|
-
[
|
|
1306
|
+
[f, t],
|
|
1307
1307
|
e.onError
|
|
1308
1308
|
);
|
|
1309
1309
|
if (!g)
|
|
@@ -1312,7 +1312,7 @@ function ar(e, r) {
|
|
|
1312
1312
|
error: "Failed to create or retrieve user",
|
|
1313
1313
|
errorCode: m.VALIDATION_ERROR
|
|
1314
1314
|
};
|
|
1315
|
-
const w = e.createSession(g,
|
|
1315
|
+
const w = e.createSession(g, f, a);
|
|
1316
1316
|
return await e.saveSession(w), e.callbacks.onSignIn && await q(
|
|
1317
1317
|
e.callbacks.onSignIn,
|
|
1318
1318
|
[w.user, w],
|
|
@@ -1364,42 +1364,49 @@ function st(e) {
|
|
|
1364
1364
|
}, t = e.actions, n = e.callbacks || {}, s = ((L = e.providers) == null ? void 0 : L.oauth) || {}, o = Ze(), i = {
|
|
1365
1365
|
...Qe(),
|
|
1366
1366
|
...e.tokenRefresh
|
|
1367
|
-
}, a = ((M = e.session) == null ? void 0 : M.cacheTtl) ?? e.sessionCacheTtl ?? 5e3, u = e.oauthStateStore || Be(),
|
|
1367
|
+
}, a = ((M = e.session) == null ? void 0 : M.cacheTtl) ?? e.sessionCacheTtl ?? 5e3, u = e.oauthStateStore || Be(), f = { ...t }, g = async (c, l) => {
|
|
1368
1368
|
const d = {
|
|
1369
|
-
provider:
|
|
1369
|
+
provider: l,
|
|
1370
1370
|
expiresAt: Date.now() + 6e5
|
|
1371
1371
|
// 10 minutes
|
|
1372
1372
|
};
|
|
1373
1373
|
await Promise.resolve(u.set(c, d, 10 * 60 * 1e3)), u.cleanup && await Promise.resolve(u.cleanup());
|
|
1374
|
-
}, w = async (c,
|
|
1375
|
-
|
|
1376
|
-
|
|
1374
|
+
}, w = async (c, l) => {
|
|
1375
|
+
let d = await Promise.resolve(u.get(c));
|
|
1376
|
+
if (!d)
|
|
1377
|
+
try {
|
|
1378
|
+
const { getOAuthStateCookie: v } = await import("../oauth-state-DKle8eCr.mjs").then((P) => P.q), C = await v();
|
|
1379
|
+
if (C && C.state === c && C.provider === l)
|
|
1380
|
+
return !0;
|
|
1381
|
+
} catch {
|
|
1382
|
+
}
|
|
1383
|
+
return d ? d.expiresAt < Date.now() ? (await Promise.resolve(u.delete(c)), !1) : d.provider !== l ? !1 : (await Promise.resolve(u.delete(c)), !0) : !1;
|
|
1377
1384
|
}, R = cr(
|
|
1378
1385
|
s,
|
|
1379
1386
|
o,
|
|
1380
1387
|
_e,
|
|
1381
1388
|
Ne
|
|
1382
1389
|
);
|
|
1383
|
-
if (R && !
|
|
1384
|
-
const c =
|
|
1385
|
-
|
|
1390
|
+
if (R && !f.signIn.oauth) {
|
|
1391
|
+
const c = f.signIn;
|
|
1392
|
+
f.signIn = {
|
|
1386
1393
|
...c,
|
|
1387
|
-
oauth: async (
|
|
1388
|
-
const d = await R(
|
|
1389
|
-
return await g(d.state,
|
|
1394
|
+
oauth: async (l) => {
|
|
1395
|
+
const d = await R(l);
|
|
1396
|
+
return await g(d.state, l), d;
|
|
1390
1397
|
}
|
|
1391
1398
|
};
|
|
1392
1399
|
}
|
|
1393
|
-
if (!
|
|
1400
|
+
if (!f.signIn || !f.signIn.email)
|
|
1394
1401
|
throw new Error("mulguard: signIn.email action is required");
|
|
1395
|
-
const
|
|
1402
|
+
const A = async (c, ...l) => {
|
|
1396
1403
|
if (c)
|
|
1397
1404
|
try {
|
|
1398
|
-
return await c(...
|
|
1405
|
+
return await c(...l);
|
|
1399
1406
|
} catch (d) {
|
|
1400
1407
|
throw n.onError && await n.onError(d instanceof Error ? d : new Error(String(d)), "callback"), d;
|
|
1401
1408
|
}
|
|
1402
|
-
},
|
|
1409
|
+
}, S = er({
|
|
1403
1410
|
sessionConfig: r,
|
|
1404
1411
|
cacheTtl: a,
|
|
1405
1412
|
getSessionAction: t.getSession,
|
|
@@ -1408,45 +1415,45 @@ function st(e) {
|
|
|
1408
1415
|
}), y = async (c) => {
|
|
1409
1416
|
if (!D(c) || !c.session)
|
|
1410
1417
|
return { success: !0 };
|
|
1411
|
-
const
|
|
1412
|
-
return c.user && n.onSignIn && await
|
|
1418
|
+
const l = await S.setSession(c.session);
|
|
1419
|
+
return c.user && n.onSignIn && await A(n.onSignIn, c.user, c.session), l;
|
|
1413
1420
|
};
|
|
1414
|
-
if (Object.keys(s).length > 0 && !
|
|
1421
|
+
if (Object.keys(s).length > 0 && !f.oauthCallback) {
|
|
1415
1422
|
const c = ar(
|
|
1416
1423
|
{
|
|
1417
1424
|
oauthProviders: s,
|
|
1418
1425
|
baseUrl: o,
|
|
1419
1426
|
callbacks: n,
|
|
1420
|
-
createSession: (
|
|
1427
|
+
createSession: (l, d, v) => ({
|
|
1421
1428
|
user: {
|
|
1422
|
-
...
|
|
1429
|
+
...l,
|
|
1423
1430
|
avatar: d.avatar,
|
|
1424
1431
|
emailVerified: d.emailVerified
|
|
1425
1432
|
},
|
|
1426
1433
|
expiresAt: new Date(Date.now() + (r.expiresIn || 604800) * 1e3),
|
|
1427
|
-
accessToken:
|
|
1428
|
-
refreshToken:
|
|
1434
|
+
accessToken: v.access_token,
|
|
1435
|
+
refreshToken: v.refresh_token,
|
|
1429
1436
|
tokenType: "Bearer",
|
|
1430
|
-
expiresIn:
|
|
1437
|
+
expiresIn: v.expires_in
|
|
1431
1438
|
}),
|
|
1432
|
-
saveSession: async (
|
|
1433
|
-
await
|
|
1439
|
+
saveSession: async (l) => {
|
|
1440
|
+
await S.setSession(l);
|
|
1434
1441
|
},
|
|
1435
1442
|
onError: n.onError
|
|
1436
1443
|
}
|
|
1437
1444
|
);
|
|
1438
|
-
|
|
1445
|
+
f.oauthCallback = c;
|
|
1439
1446
|
}
|
|
1440
1447
|
const h = or(
|
|
1441
1448
|
{
|
|
1442
|
-
actions:
|
|
1449
|
+
actions: f,
|
|
1443
1450
|
callbacks: n,
|
|
1444
1451
|
saveSessionAfterAuth: y,
|
|
1445
1452
|
onError: n.onError
|
|
1446
1453
|
},
|
|
1447
1454
|
g
|
|
1448
1455
|
), T = ir({
|
|
1449
|
-
actions:
|
|
1456
|
+
actions: f,
|
|
1450
1457
|
callbacks: n,
|
|
1451
1458
|
saveSessionAfterAuth: y,
|
|
1452
1459
|
onError: n.onError
|
|
@@ -1456,25 +1463,25 @@ function st(e) {
|
|
|
1456
1463
|
* Uses custom getSession action if provided, otherwise falls back to reading from cookie
|
|
1457
1464
|
*/
|
|
1458
1465
|
async getSession() {
|
|
1459
|
-
return await
|
|
1466
|
+
return await S.getSession();
|
|
1460
1467
|
},
|
|
1461
1468
|
/**
|
|
1462
1469
|
* Get access token from current session
|
|
1463
1470
|
*/
|
|
1464
1471
|
async getAccessToken() {
|
|
1465
|
-
return await
|
|
1472
|
+
return await S.getAccessToken();
|
|
1466
1473
|
},
|
|
1467
1474
|
/**
|
|
1468
1475
|
* Get refresh token from current session
|
|
1469
1476
|
*/
|
|
1470
1477
|
async getRefreshToken() {
|
|
1471
|
-
return await
|
|
1478
|
+
return await S.getRefreshToken();
|
|
1472
1479
|
},
|
|
1473
1480
|
/**
|
|
1474
1481
|
* Check if session has valid tokens
|
|
1475
1482
|
*/
|
|
1476
1483
|
async hasValidTokens() {
|
|
1477
|
-
return await
|
|
1484
|
+
return await S.hasValidTokens();
|
|
1478
1485
|
},
|
|
1479
1486
|
/**
|
|
1480
1487
|
* Unified sign in method - supports both unified and direct method calls
|
|
@@ -1493,10 +1500,10 @@ function st(e) {
|
|
|
1493
1500
|
*/
|
|
1494
1501
|
async signOut() {
|
|
1495
1502
|
try {
|
|
1496
|
-
const c = await this.getSession(),
|
|
1497
|
-
return t.signOut && await t.signOut(), await
|
|
1503
|
+
const c = await this.getSession(), l = c == null ? void 0 : c.user;
|
|
1504
|
+
return t.signOut && await t.signOut(), await S.clearSessionCookie(), S.clearCache(), l && n.onSignOut && await A(n.onSignOut, l), { success: !0 };
|
|
1498
1505
|
} catch (c) {
|
|
1499
|
-
return await
|
|
1506
|
+
return await S.clearSessionCookie(), S.clearCache(), n.onError && await A(n.onError, c instanceof Error ? c : new Error(String(c)), "signOut"), {
|
|
1500
1507
|
success: !1,
|
|
1501
1508
|
error: c instanceof Error ? c.message : "Sign out failed"
|
|
1502
1509
|
};
|
|
@@ -1510,10 +1517,10 @@ function st(e) {
|
|
|
1510
1517
|
throw new Error("Password reset is not configured. Provide resetPassword action in config.");
|
|
1511
1518
|
try {
|
|
1512
1519
|
return await t.resetPassword(c);
|
|
1513
|
-
} catch (
|
|
1514
|
-
return n.onError && await
|
|
1520
|
+
} catch (l) {
|
|
1521
|
+
return n.onError && await A(n.onError, l instanceof Error ? l : new Error(String(l)), "resetPassword"), {
|
|
1515
1522
|
success: !1,
|
|
1516
|
-
error:
|
|
1523
|
+
error: l instanceof Error ? l.message : "Password reset failed"
|
|
1517
1524
|
};
|
|
1518
1525
|
}
|
|
1519
1526
|
},
|
|
@@ -1525,10 +1532,10 @@ function st(e) {
|
|
|
1525
1532
|
throw new Error("Email verification is not configured. Provide verifyEmail action in config.");
|
|
1526
1533
|
try {
|
|
1527
1534
|
return await t.verifyEmail(c);
|
|
1528
|
-
} catch (
|
|
1529
|
-
return n.onError && await
|
|
1535
|
+
} catch (l) {
|
|
1536
|
+
return n.onError && await A(n.onError, l instanceof Error ? l : new Error(String(l)), "verifyEmail"), {
|
|
1530
1537
|
success: !1,
|
|
1531
|
-
error:
|
|
1538
|
+
error: l instanceof Error ? l.message : "Email verification failed"
|
|
1532
1539
|
};
|
|
1533
1540
|
}
|
|
1534
1541
|
},
|
|
@@ -1542,48 +1549,48 @@ function st(e) {
|
|
|
1542
1549
|
try {
|
|
1543
1550
|
const c = await t.refreshSession();
|
|
1544
1551
|
if (c && U(c)) {
|
|
1545
|
-
if (await
|
|
1546
|
-
const
|
|
1547
|
-
if (
|
|
1548
|
-
if (await
|
|
1552
|
+
if (await S.setSession(c), n.onSessionUpdate) {
|
|
1553
|
+
const l = await A(n.onSessionUpdate, c);
|
|
1554
|
+
if (l && U(l)) {
|
|
1555
|
+
if (await S.setSession(l), n.onTokenRefresh) {
|
|
1549
1556
|
const d = await this.getSession();
|
|
1550
|
-
d && await
|
|
1557
|
+
d && await A(n.onTokenRefresh, d, l);
|
|
1551
1558
|
}
|
|
1552
|
-
return
|
|
1559
|
+
return l;
|
|
1553
1560
|
}
|
|
1554
1561
|
}
|
|
1555
1562
|
if (n.onTokenRefresh) {
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1563
|
+
const l = await this.getSession();
|
|
1564
|
+
l && await A(n.onTokenRefresh, l, c);
|
|
1558
1565
|
}
|
|
1559
1566
|
return c;
|
|
1560
1567
|
} else if (c && !U(c))
|
|
1561
|
-
return await
|
|
1568
|
+
return await S.clearSessionCookie(), S.clearCache(), null;
|
|
1562
1569
|
return null;
|
|
1563
1570
|
} catch (c) {
|
|
1564
|
-
return await
|
|
1571
|
+
return await S.clearSessionCookie(), S.clearCache(), n.onError && await A(n.onError, c instanceof Error ? c : new Error(String(c)), "refreshSession"), null;
|
|
1565
1572
|
}
|
|
1566
1573
|
},
|
|
1567
1574
|
/**
|
|
1568
1575
|
* OAuth callback handler
|
|
1569
1576
|
* ✅ Auto-generated if providers.oauth is configured in config
|
|
1570
1577
|
*/
|
|
1571
|
-
async oauthCallback(c,
|
|
1572
|
-
if (!
|
|
1578
|
+
async oauthCallback(c, l, d) {
|
|
1579
|
+
if (!f.oauthCallback)
|
|
1573
1580
|
throw new Error(
|
|
1574
1581
|
"OAuth callback is not configured. Either provide oauthCallback action, or configure providers.oauth in config."
|
|
1575
1582
|
);
|
|
1576
|
-
if (!
|
|
1583
|
+
if (!l || !d)
|
|
1577
1584
|
return {
|
|
1578
1585
|
success: !1,
|
|
1579
1586
|
error: "Missing required OAuth parameters (code or state)",
|
|
1580
1587
|
errorCode: m.VALIDATION_ERROR
|
|
1581
1588
|
};
|
|
1582
|
-
let
|
|
1583
|
-
if (!
|
|
1589
|
+
let v = c;
|
|
1590
|
+
if (!v) {
|
|
1584
1591
|
const P = await Promise.resolve(u.get(d));
|
|
1585
1592
|
if (P && P.provider)
|
|
1586
|
-
|
|
1593
|
+
v = P.provider;
|
|
1587
1594
|
else
|
|
1588
1595
|
return {
|
|
1589
1596
|
success: !1,
|
|
@@ -1591,16 +1598,16 @@ function st(e) {
|
|
|
1591
1598
|
errorCode: m.VALIDATION_ERROR
|
|
1592
1599
|
};
|
|
1593
1600
|
}
|
|
1594
|
-
if (!await w(d,
|
|
1601
|
+
if (!await w(d, v))
|
|
1595
1602
|
return {
|
|
1596
1603
|
success: !1,
|
|
1597
1604
|
error: "Invalid or expired state parameter",
|
|
1598
1605
|
errorCode: m.VALIDATION_ERROR
|
|
1599
1606
|
};
|
|
1600
1607
|
try {
|
|
1601
|
-
return await
|
|
1608
|
+
return await f.oauthCallback(v, l, d);
|
|
1602
1609
|
} catch (P) {
|
|
1603
|
-
return n.onError && await
|
|
1610
|
+
return n.onError && await A(n.onError, P instanceof Error ? P : new Error(String(P)), "oauthCallback"), {
|
|
1604
1611
|
success: !1,
|
|
1605
1612
|
error: P instanceof Error ? P.message : "OAuth callback failed",
|
|
1606
1613
|
errorCode: m.NETWORK_ERROR
|
|
@@ -1611,25 +1618,25 @@ function st(e) {
|
|
|
1611
1618
|
* Verify 2FA code after initial sign in
|
|
1612
1619
|
* Used when signIn returns requires2FA: true
|
|
1613
1620
|
*/
|
|
1614
|
-
async verify2FA(c,
|
|
1621
|
+
async verify2FA(c, l) {
|
|
1615
1622
|
if (!t.verify2FA)
|
|
1616
1623
|
throw new Error("2FA verification is not configured. Provide verify2FA action in config.");
|
|
1617
1624
|
try {
|
|
1618
1625
|
const d = await t.verify2FA(c);
|
|
1619
|
-
if (d.success && d.session && !(
|
|
1620
|
-
const
|
|
1621
|
-
|
|
1622
|
-
error:
|
|
1623
|
-
warning:
|
|
1624
|
-
}), n.onError && await
|
|
1626
|
+
if (d.success && d.session && !(l != null && l.skipCookieSave)) {
|
|
1627
|
+
const v = await y(d);
|
|
1628
|
+
v.success || (process.env.NODE_ENV === "development" && I.debug("Failed to save session cookie after verify2FA", {
|
|
1629
|
+
error: v.error,
|
|
1630
|
+
warning: v.warning
|
|
1631
|
+
}), n.onError && await A(
|
|
1625
1632
|
n.onError,
|
|
1626
|
-
new Error(
|
|
1633
|
+
new Error(v.warning || v.error || "Failed to save session cookie"),
|
|
1627
1634
|
"verify2FA.setSession"
|
|
1628
1635
|
));
|
|
1629
1636
|
}
|
|
1630
1637
|
return d;
|
|
1631
1638
|
} catch (d) {
|
|
1632
|
-
return n.onError && await
|
|
1639
|
+
return n.onError && await A(n.onError, d instanceof Error ? d : new Error(String(d)), "verify2FA"), {
|
|
1633
1640
|
success: !1,
|
|
1634
1641
|
error: d instanceof Error ? d.message : "2FA verification failed",
|
|
1635
1642
|
errorCode: m.TWO_FA_REQUIRED
|
|
@@ -1641,7 +1648,7 @@ function st(e) {
|
|
|
1641
1648
|
* Useful for Server Actions that need to save session manually
|
|
1642
1649
|
*/
|
|
1643
1650
|
async setSession(c) {
|
|
1644
|
-
return await
|
|
1651
|
+
return await S.setSession(c);
|
|
1645
1652
|
},
|
|
1646
1653
|
/**
|
|
1647
1654
|
* Internal method to get session config for Server Actions
|
|
@@ -1649,7 +1656,7 @@ function st(e) {
|
|
|
1649
1656
|
* @internal
|
|
1650
1657
|
*/
|
|
1651
1658
|
_getSessionConfig() {
|
|
1652
|
-
return
|
|
1659
|
+
return S.getSessionConfig();
|
|
1653
1660
|
},
|
|
1654
1661
|
_getCallbacks() {
|
|
1655
1662
|
return n;
|
|
@@ -1661,8 +1668,8 @@ function st(e) {
|
|
|
1661
1668
|
* @param state - OAuth state token
|
|
1662
1669
|
* @param provider - OAuth provider name
|
|
1663
1670
|
*/
|
|
1664
|
-
async storeOAuthState(c,
|
|
1665
|
-
await g(c,
|
|
1671
|
+
async storeOAuthState(c, l) {
|
|
1672
|
+
await g(c, l);
|
|
1666
1673
|
},
|
|
1667
1674
|
/**
|
|
1668
1675
|
* PassKey methods
|
|
@@ -1670,22 +1677,22 @@ function st(e) {
|
|
|
1670
1677
|
passkey: t.passkey ? {
|
|
1671
1678
|
register: t.passkey.register,
|
|
1672
1679
|
authenticate: async (c) => {
|
|
1673
|
-
var
|
|
1674
|
-
if (!((
|
|
1680
|
+
var l;
|
|
1681
|
+
if (!((l = t.passkey) != null && l.authenticate))
|
|
1675
1682
|
throw new Error("PassKey authenticate is not configured.");
|
|
1676
1683
|
try {
|
|
1677
1684
|
const d = await t.passkey.authenticate(c);
|
|
1678
1685
|
return d.success && d.session && await y(d), d;
|
|
1679
1686
|
} catch (d) {
|
|
1680
|
-
return n.onError && await
|
|
1687
|
+
return n.onError && await A(n.onError, d instanceof Error ? d : new Error(String(d)), "passkey.authenticate"), {
|
|
1681
1688
|
success: !1,
|
|
1682
1689
|
error: d instanceof Error ? d.message : "PassKey authentication failed"
|
|
1683
1690
|
};
|
|
1684
1691
|
}
|
|
1685
1692
|
},
|
|
1686
1693
|
list: t.passkey.list ? async () => {
|
|
1687
|
-
var
|
|
1688
|
-
if (!((
|
|
1694
|
+
var l;
|
|
1695
|
+
if (!((l = t.passkey) != null && l.list))
|
|
1689
1696
|
throw new Error("PassKey list is not configured.");
|
|
1690
1697
|
return [...await t.passkey.list()];
|
|
1691
1698
|
} : void 0,
|
|
@@ -1702,27 +1709,27 @@ function st(e) {
|
|
|
1702
1709
|
isEnabled: t.twoFactor.isEnabled,
|
|
1703
1710
|
verify2FA: async (c) => {
|
|
1704
1711
|
var d;
|
|
1705
|
-
const
|
|
1706
|
-
if (!
|
|
1712
|
+
const l = ((d = t.twoFactor) == null ? void 0 : d.verify2FA) || t.verify2FA;
|
|
1713
|
+
if (!l)
|
|
1707
1714
|
throw new Error("2FA verification is not configured. Provide verify2FA action in config.");
|
|
1708
1715
|
try {
|
|
1709
|
-
const
|
|
1710
|
-
if (
|
|
1711
|
-
const C = await y(
|
|
1716
|
+
const v = await l(c);
|
|
1717
|
+
if (v.success && v.session) {
|
|
1718
|
+
const C = await y(v);
|
|
1712
1719
|
C.success || (process.env.NODE_ENV === "development" && I.debug("Failed to save session cookie after twoFactor.verify2FA", {
|
|
1713
1720
|
error: C.error,
|
|
1714
1721
|
warning: C.warning
|
|
1715
|
-
}), n.onError && await
|
|
1722
|
+
}), n.onError && await A(
|
|
1716
1723
|
n.onError,
|
|
1717
1724
|
new Error(C.warning || C.error || "Failed to save session cookie"),
|
|
1718
1725
|
"twoFactor.verify2FA.setSession"
|
|
1719
1726
|
));
|
|
1720
1727
|
}
|
|
1721
|
-
return
|
|
1722
|
-
} catch (
|
|
1723
|
-
return n.onError && await
|
|
1728
|
+
return v;
|
|
1729
|
+
} catch (v) {
|
|
1730
|
+
return n.onError && await A(n.onError, v instanceof Error ? v : new Error(String(v)), "twoFactor.verify2FA"), {
|
|
1724
1731
|
success: !1,
|
|
1725
|
-
error:
|
|
1732
|
+
error: v instanceof Error ? v.message : "2FA verification failed",
|
|
1726
1733
|
errorCode: m.UNKNOWN_ERROR
|
|
1727
1734
|
};
|
|
1728
1735
|
}
|
|
@@ -1734,16 +1741,16 @@ function st(e) {
|
|
|
1734
1741
|
signInMethods: {
|
|
1735
1742
|
email: (c) => h.email(c),
|
|
1736
1743
|
oauth: (c) => {
|
|
1737
|
-
var
|
|
1738
|
-
return ((
|
|
1744
|
+
var l;
|
|
1745
|
+
return ((l = h.oauth) == null ? void 0 : l.call(h, c)) || Promise.reject(new Error("OAuth not configured"));
|
|
1739
1746
|
},
|
|
1740
1747
|
passkey: (c) => {
|
|
1741
|
-
var
|
|
1742
|
-
return ((
|
|
1748
|
+
var l;
|
|
1749
|
+
return ((l = h.passkey) == null ? void 0 : l.call(h, c)) || Promise.reject(new Error("Passkey not configured"));
|
|
1743
1750
|
},
|
|
1744
|
-
otp: (c,
|
|
1751
|
+
otp: (c, l) => {
|
|
1745
1752
|
var d;
|
|
1746
|
-
return ((d = h.otp) == null ? void 0 : d.call(h, c,
|
|
1753
|
+
return ((d = h.otp) == null ? void 0 : d.call(h, c, l)) || Promise.reject(new Error("OTP not configured"));
|
|
1747
1754
|
}
|
|
1748
1755
|
}
|
|
1749
1756
|
};
|
|
@@ -1752,7 +1759,7 @@ function st(e) {
|
|
|
1752
1759
|
async () => await _.refreshSession(),
|
|
1753
1760
|
async () => await _.signOut(),
|
|
1754
1761
|
async () => {
|
|
1755
|
-
await
|
|
1762
|
+
await S.clearSessionCookie(), S.clearCache();
|
|
1756
1763
|
},
|
|
1757
1764
|
{
|
|
1758
1765
|
...i,
|
|
@@ -1815,11 +1822,11 @@ function re(e, r) {
|
|
|
1815
1822
|
async function te(e, r, t, n, s, o, i) {
|
|
1816
1823
|
if (!r.oauthCallback)
|
|
1817
1824
|
return o === "GET" ? V(e.url, "oauth_not_configured") : O("OAuth callback is not configured", 400);
|
|
1818
|
-
const a = hr(n, s, i), u = (i == null ? void 0 : i.code) ?? s.searchParams.get("code"),
|
|
1819
|
-
if (!u || !
|
|
1825
|
+
const a = hr(n, s, i), u = (i == null ? void 0 : i.code) ?? s.searchParams.get("code"), f = (i == null ? void 0 : i.state) ?? s.searchParams.get("state");
|
|
1826
|
+
if (!u || !f)
|
|
1820
1827
|
return o === "GET" ? V(e.url, "oauth_missing_params") : O("Missing required OAuth parameters. Code and state are required.", 400);
|
|
1821
1828
|
try {
|
|
1822
|
-
const g = await r.oauthCallback(a ?? "", u,
|
|
1829
|
+
const g = await r.oauthCallback(a ?? "", u, f);
|
|
1823
1830
|
return o === "GET" ? g.success ? Ar(e.url, s.searchParams.get("callbackUrl")) : V(e.url, g.error ?? "oauth_failed") : E.json(g);
|
|
1824
1831
|
} catch (g) {
|
|
1825
1832
|
return o === "GET" ? V(e.url, g instanceof Error ? g.message : "oauth_error") : O(g instanceof Error ? g.message : "OAuth callback failed", 500);
|
|
@@ -1980,8 +1987,8 @@ function it(e) {
|
|
|
1980
1987
|
},
|
|
1981
1988
|
body: i ? JSON.stringify(i) : void 0
|
|
1982
1989
|
}
|
|
1983
|
-
),
|
|
1984
|
-
return E.json(
|
|
1990
|
+
), f = await u.json();
|
|
1991
|
+
return E.json(f, {
|
|
1985
1992
|
status: u.status,
|
|
1986
1993
|
headers: {
|
|
1987
1994
|
...Object.fromEntries(u.headers.entries())
|
|
@@ -2055,21 +2062,21 @@ function ut(e, r = {}) {
|
|
|
2055
2062
|
} = r;
|
|
2056
2063
|
return async (i) => {
|
|
2057
2064
|
const { pathname: a } = i.nextUrl, u = t.some((w) => a.startsWith(w));
|
|
2058
|
-
let
|
|
2065
|
+
let f = null;
|
|
2059
2066
|
try {
|
|
2060
|
-
|
|
2067
|
+
f = await e.getSession();
|
|
2061
2068
|
} catch (w) {
|
|
2062
2069
|
console.error("Middleware: Failed to get session:", w);
|
|
2063
2070
|
}
|
|
2064
|
-
if (u && !
|
|
2071
|
+
if (u && !f) {
|
|
2065
2072
|
const w = i.nextUrl.clone();
|
|
2066
2073
|
return w.pathname = s, w.searchParams.set("callbackUrl", a), E.redirect(w);
|
|
2067
2074
|
}
|
|
2068
|
-
if (o &&
|
|
2075
|
+
if (o && f && (a.startsWith("/login") || a.startsWith("/register"))) {
|
|
2069
2076
|
const R = i.nextUrl.clone();
|
|
2070
2077
|
R.pathname = o;
|
|
2071
|
-
const
|
|
2072
|
-
return F(i,
|
|
2078
|
+
const A = E.redirect(R);
|
|
2079
|
+
return F(i, A);
|
|
2073
2080
|
}
|
|
2074
2081
|
const g = E.next();
|
|
2075
2082
|
return F(i, g);
|
|
@@ -2099,25 +2106,25 @@ function ft(e) {
|
|
|
2099
2106
|
const R = E.next();
|
|
2100
2107
|
return F(a, R);
|
|
2101
2108
|
}
|
|
2102
|
-
const
|
|
2109
|
+
const f = t.some((R) => u.startsWith(R));
|
|
2103
2110
|
let g = null;
|
|
2104
|
-
if (
|
|
2111
|
+
if (f || o)
|
|
2105
2112
|
try {
|
|
2106
2113
|
g = await r.getSession();
|
|
2107
2114
|
} catch (R) {
|
|
2108
2115
|
console.error("Middleware: Failed to get session:", R);
|
|
2109
2116
|
}
|
|
2110
|
-
if (
|
|
2117
|
+
if (f && !g) {
|
|
2111
2118
|
const R = a.nextUrl.clone();
|
|
2112
2119
|
R.pathname = s, R.searchParams.set("callbackUrl", u);
|
|
2113
|
-
const
|
|
2114
|
-
return F(a,
|
|
2120
|
+
const A = E.redirect(R);
|
|
2121
|
+
return F(a, A);
|
|
2115
2122
|
}
|
|
2116
2123
|
if (o && g && (u.startsWith("/login") || u.startsWith("/register"))) {
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2119
|
-
const
|
|
2120
|
-
return F(a,
|
|
2124
|
+
const A = a.nextUrl.clone();
|
|
2125
|
+
A.pathname = o;
|
|
2126
|
+
const S = E.redirect(A);
|
|
2127
|
+
return F(a, S);
|
|
2121
2128
|
}
|
|
2122
2129
|
const w = E.next();
|
|
2123
2130
|
return F(a, w);
|