mulguard 1.1.6 → 1.1.7
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/README.md +210 -706
- package/dist/actions-CMtg7FGv.js +1 -0
- package/dist/{actions-DeCfLtHA.mjs → actions-CjQUKaXF.mjs} +54 -38
- package/dist/client/index.js +1 -1
- package/dist/client/index.mjs +84 -78
- package/dist/core/auth/email-password.d.ts +145 -0
- package/dist/core/auth/oauth/index.d.ts +14 -0
- package/dist/core/auth/oauth/oauth-handler.d.ts +172 -0
- package/dist/core/auth/oauth/pkce.d.ts +168 -0
- package/dist/core/auth/{oauth-providers.d.ts → oauth/providers.d.ts} +8 -7
- package/dist/core/auth/{oauth-state-store-cookie.d.ts → oauth/state-store-cookie.d.ts} +4 -4
- package/dist/core/auth/{oauth-state-store-redis.d.ts → oauth/state-store-redis.d.ts} +1 -1
- package/dist/core/auth/{oauth-state-store.d.ts → oauth/state-store.d.ts} +4 -1
- package/dist/core/auth/otp.d.ts +184 -0
- package/dist/core/errors/index.d.ts +269 -0
- package/dist/core/index.d.ts +1 -3
- package/dist/core/logger/index.d.ts +147 -0
- package/dist/core/mulguard/integration.d.ts +104 -0
- package/dist/core/mulguard/oauth-handler.d.ts +1 -1
- package/dist/core/security/security-manager.d.ts +236 -0
- package/dist/core/session/session-manager.d.ts +235 -0
- package/dist/core/types/index.d.ts +27 -5
- package/dist/index/index.js +1 -1
- package/dist/index/index.mjs +1388 -881
- package/dist/index.d.ts +3 -6
- package/dist/{client → nextjs/client}/hooks.d.ts +2 -2
- package/dist/nextjs/client/index.d.ts +13 -0
- package/dist/{client → nextjs/client}/provider.d.ts +1 -1
- package/dist/{client → nextjs/client}/server-actions-helper.d.ts +2 -2
- package/dist/{handlers → nextjs/handlers}/api.d.ts +1 -1
- package/dist/nextjs/handlers/index.d.ts +9 -0
- package/dist/{handlers → nextjs/handlers}/route.d.ts +1 -1
- package/dist/nextjs/index.d.ts +15 -0
- package/dist/nextjs/proxy/index.d.ts +149 -0
- package/dist/nextjs/server/actions.d.ts +30 -0
- package/dist/{server → nextjs/server}/auth.d.ts +6 -6
- package/dist/{server → nextjs/server}/cookies.d.ts +5 -6
- package/dist/nextjs/server/index.d.ts +18 -0
- package/dist/{server → nextjs/server}/oauth-state.d.ts +5 -3
- package/dist/{server → nextjs/server}/session-helpers.d.ts +1 -3
- package/dist/nextjs/server/session.d.ts +144 -0
- package/dist/oauth-state-Drwz6fES.js +1 -0
- package/dist/oauth-state-pdypStuS.mjs +210 -0
- package/dist/server/index.js +1 -1
- package/dist/server/index.mjs +27 -29
- package/package.json +64 -11
- package/dist/actions-CExpv_dD.js +0 -1
- package/dist/client/index.d.ts +0 -5
- package/dist/core/auth/index.d.ts +0 -40
- package/dist/core/auth/oauth.d.ts +0 -20
- package/dist/middleware/index.d.ts +0 -28
- package/dist/middleware/proxy.d.ts +0 -53
- package/dist/oauth-state-DKle8eCr.mjs +0 -289
- package/dist/oauth-state-DlvrCV11.js +0 -1
- package/dist/server/actions.d.ts +0 -86
- package/dist/server/helpers.d.ts +0 -10
- package/dist/server/index.d.ts +0 -14
- package/dist/server/middleware.d.ts +0 -39
- package/dist/server/session.d.ts +0 -28
- package/dist/server/utils.d.ts +0 -10
- /package/dist/{middleware → nextjs/proxy}/security.d.ts +0 -0
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { d as f, g as R, c as v } from "./actions-DeCfLtHA.mjs";
|
|
2
|
-
import { redirect as T } from "next/navigation";
|
|
3
|
-
import { NextResponse as w } from "next/server";
|
|
4
|
-
function p(e) {
|
|
5
|
-
return !e || !e.expiresAt ? !1 : new Date(e.expiresAt) < /* @__PURE__ */ new Date();
|
|
6
|
-
}
|
|
7
|
-
function U(e, t = 5) {
|
|
8
|
-
if (!e || !e.expiresAt)
|
|
9
|
-
return !1;
|
|
10
|
-
const r = new Date(e.expiresAt), s = /* @__PURE__ */ new Date(), i = (r.getTime() - s.getTime()) / (1e3 * 60);
|
|
11
|
-
return i > 0 && i < t;
|
|
12
|
-
}
|
|
13
|
-
function q(e) {
|
|
14
|
-
if (!e || !e.expiresAt)
|
|
15
|
-
return null;
|
|
16
|
-
const t = new Date(e.expiresAt), r = /* @__PURE__ */ new Date(), s = (t.getTime() - r.getTime()) / (1e3 * 60);
|
|
17
|
-
return s > 0 ? Math.floor(s) : 0;
|
|
18
|
-
}
|
|
19
|
-
function M(e) {
|
|
20
|
-
return !(!e || !e.user || !e.user.id || !e.user.email || !e.user.name || p(e));
|
|
21
|
-
}
|
|
22
|
-
function m(e) {
|
|
23
|
-
if (!e || typeof e != "object")
|
|
24
|
-
return !1;
|
|
25
|
-
const t = e;
|
|
26
|
-
if (!t.user || typeof t.user != "object")
|
|
27
|
-
return !1;
|
|
28
|
-
const r = t.user;
|
|
29
|
-
if (typeof r.id != "string" || r.id.length === 0 || typeof r.email != "string" || r.email.length === 0 || typeof r.name != "string" || r.name.length === 0 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r.email))
|
|
30
|
-
return !1;
|
|
31
|
-
if (t.expiresAt)
|
|
32
|
-
if (t.expiresAt instanceof Date) {
|
|
33
|
-
if (isNaN(t.expiresAt.getTime()))
|
|
34
|
-
return !1;
|
|
35
|
-
} else if (typeof t.expiresAt == "string") {
|
|
36
|
-
const i = new Date(t.expiresAt);
|
|
37
|
-
if (isNaN(i.getTime()))
|
|
38
|
-
return !1;
|
|
39
|
-
} else
|
|
40
|
-
return !1;
|
|
41
|
-
return !0;
|
|
42
|
-
}
|
|
43
|
-
function j(e, t) {
|
|
44
|
-
const r = t.cookieName || "__mulguard_session";
|
|
45
|
-
let s = null, i = 0;
|
|
46
|
-
const h = 6e4;
|
|
47
|
-
return {
|
|
48
|
-
/**
|
|
49
|
-
* Get current session from backend with automatic refresh
|
|
50
|
-
*/
|
|
51
|
-
async getSession(n) {
|
|
52
|
-
try {
|
|
53
|
-
if (!await R(r))
|
|
54
|
-
return s = null, null;
|
|
55
|
-
const o = Date.now();
|
|
56
|
-
if (s && o - i < h) {
|
|
57
|
-
if (!(n != null && n.skipRefresh) && this.shouldRefreshSession(s, t)) {
|
|
58
|
-
const u = await this.refreshSession();
|
|
59
|
-
if (u)
|
|
60
|
-
return s = u, i = o, u;
|
|
61
|
-
}
|
|
62
|
-
return s;
|
|
63
|
-
}
|
|
64
|
-
const c = await e.get("/api/auth/session");
|
|
65
|
-
if (!c.data.session)
|
|
66
|
-
return s = null, null;
|
|
67
|
-
const l = c.data.session;
|
|
68
|
-
if (!m(l))
|
|
69
|
-
return await f(r), s = null, null;
|
|
70
|
-
if (p(l)) {
|
|
71
|
-
if (!(n != null && n.skipRefresh) && this.shouldRefreshSession(l, t)) {
|
|
72
|
-
const u = await this.refreshSession();
|
|
73
|
-
if (u)
|
|
74
|
-
return s = u, i = o, u;
|
|
75
|
-
}
|
|
76
|
-
return await f(r), s = null, null;
|
|
77
|
-
}
|
|
78
|
-
if (!(n != null && n.skipRefresh) && this.shouldRefreshSession(l, t)) {
|
|
79
|
-
const u = await this.refreshSession();
|
|
80
|
-
if (u)
|
|
81
|
-
return s = u, i = o, u;
|
|
82
|
-
}
|
|
83
|
-
return s = l, i = o, l;
|
|
84
|
-
} catch {
|
|
85
|
-
return await f(r), s = null, null;
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
/**
|
|
89
|
-
* Set session cookie
|
|
90
|
-
*/
|
|
91
|
-
setSession(n, a) {
|
|
92
|
-
},
|
|
93
|
-
/**
|
|
94
|
-
* Clear session
|
|
95
|
-
*/
|
|
96
|
-
async clearSession(n) {
|
|
97
|
-
await f(r, {
|
|
98
|
-
path: n.path
|
|
99
|
-
}), s = null, i = 0;
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* Refresh session
|
|
103
|
-
*/
|
|
104
|
-
async refreshSession() {
|
|
105
|
-
try {
|
|
106
|
-
const n = await e.post("/api/auth/refresh");
|
|
107
|
-
if (!n.data.session)
|
|
108
|
-
return s = null, null;
|
|
109
|
-
const a = n.data.session;
|
|
110
|
-
return m(a) ? (s = a, i = Date.now(), a) : (s = null, null);
|
|
111
|
-
} catch {
|
|
112
|
-
return s = null, null;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* Check if session is expired
|
|
117
|
-
*/
|
|
118
|
-
isSessionExpired(n) {
|
|
119
|
-
return p(n);
|
|
120
|
-
},
|
|
121
|
-
/**
|
|
122
|
-
* Check if session should be refreshed (within 5 minutes of expiration)
|
|
123
|
-
*/
|
|
124
|
-
shouldRefreshSession(n, a) {
|
|
125
|
-
if (!n.expiresAt)
|
|
126
|
-
return !1;
|
|
127
|
-
const o = new Date(n.expiresAt), c = /* @__PURE__ */ new Date(), l = o.getTime() - c.getTime(), u = 5 * 60 * 1e3;
|
|
128
|
-
return l > 0 && l < u;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async function P(e, t) {
|
|
133
|
-
try {
|
|
134
|
-
const r = await e.post("/api/auth/refresh");
|
|
135
|
-
return r.data.session ? r.data.session : null;
|
|
136
|
-
} catch {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function g(e) {
|
|
141
|
-
try {
|
|
142
|
-
const t = await e.getSession();
|
|
143
|
-
return !t || !m(t) || p(t) ? null : t;
|
|
144
|
-
} catch (t) {
|
|
145
|
-
return console.error("Failed to get server session:", t), null;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async function S(e, t = "/login") {
|
|
149
|
-
const r = await g(e);
|
|
150
|
-
return r || T(t), r;
|
|
151
|
-
}
|
|
152
|
-
async function _(e, t, r = "/unauthorized") {
|
|
153
|
-
const s = await S(e);
|
|
154
|
-
return (!s.user.roles || !s.user.roles.includes(t)) && T(r), s;
|
|
155
|
-
}
|
|
156
|
-
async function E(e) {
|
|
157
|
-
const t = await g(e);
|
|
158
|
-
return (t == null ? void 0 : t.user) ?? null;
|
|
159
|
-
}
|
|
160
|
-
function L(e, t) {
|
|
161
|
-
return {
|
|
162
|
-
getSession: () => g(e),
|
|
163
|
-
requireAuth: (r) => S(e, r),
|
|
164
|
-
requireRole: (r, s) => _(e, r, s)
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function z(e) {
|
|
168
|
-
return {
|
|
169
|
-
getSession: () => g(e),
|
|
170
|
-
requireAuth: (t) => S(e, t),
|
|
171
|
-
requireRole: (t, r) => _(e, t, r),
|
|
172
|
-
getCurrentUser: () => E(e)
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function x(e, t = []) {
|
|
176
|
-
return [...[
|
|
177
|
-
"/auth/login",
|
|
178
|
-
"/auth/register",
|
|
179
|
-
"/auth/forgot-password",
|
|
180
|
-
"/auth/reset-password",
|
|
181
|
-
"/auth/verify-email"
|
|
182
|
-
], ...t].some((i) => e.startsWith(i));
|
|
183
|
-
}
|
|
184
|
-
function D(e, t = {}) {
|
|
185
|
-
const {
|
|
186
|
-
redirectTo: r = "/auth/login",
|
|
187
|
-
requireAuth: s = !1,
|
|
188
|
-
allowedRoles: i = [],
|
|
189
|
-
publicRoutes: h = []
|
|
190
|
-
} = t;
|
|
191
|
-
return async (n) => {
|
|
192
|
-
const { pathname: a } = n.nextUrl;
|
|
193
|
-
if (x(a, h) || a.startsWith("/api/") || a.startsWith("/_next/") || a.startsWith("/favicon.ico") || a.match(/\.(ico|png|jpg|jpeg|svg|gif|webp|css|js|woff|woff2|ttf|eot)$/))
|
|
194
|
-
return null;
|
|
195
|
-
try {
|
|
196
|
-
const o = await e.getSession();
|
|
197
|
-
if (s && !o) {
|
|
198
|
-
const c = new URL(r, n.url);
|
|
199
|
-
return c.searchParams.set("redirect", a), w.redirect(c);
|
|
200
|
-
}
|
|
201
|
-
if (o && i.length > 0) {
|
|
202
|
-
const c = o.user.roles || [];
|
|
203
|
-
if (!i.some((u) => c.includes(u)))
|
|
204
|
-
return w.redirect(new URL("/unauthorized", n.url));
|
|
205
|
-
}
|
|
206
|
-
return o && x(a, h) ? w.redirect(new URL("/", n.url)) : null;
|
|
207
|
-
} catch (o) {
|
|
208
|
-
return process.env.NODE_ENV === "development" && console.error("[Mulguard Middleware] Error:", o), null;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function H(e, t = "/auth/login") {
|
|
213
|
-
return D(e, {
|
|
214
|
-
requireAuth: !0,
|
|
215
|
-
redirectTo: t
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
function V(e, t, r = "/unauthorized") {
|
|
219
|
-
return D(e, {
|
|
220
|
-
requireAuth: !0,
|
|
221
|
-
allowedRoles: t,
|
|
222
|
-
redirectTo: r
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
const A = "__mulguard_oauth_state", y = 10 * 60;
|
|
226
|
-
async function k(e, t) {
|
|
227
|
-
try {
|
|
228
|
-
const r = JSON.stringify({ state: e, provider: t, expiresAt: Date.now() + y * 1e3 }), s = process.env.NODE_ENV === "production";
|
|
229
|
-
return await v({
|
|
230
|
-
name: A,
|
|
231
|
-
value: r,
|
|
232
|
-
httpOnly: !0,
|
|
233
|
-
secure: s,
|
|
234
|
-
sameSite: "strict",
|
|
235
|
-
maxAge: y,
|
|
236
|
-
path: "/"
|
|
237
|
-
});
|
|
238
|
-
} catch (r) {
|
|
239
|
-
return {
|
|
240
|
-
success: !1,
|
|
241
|
-
error: r instanceof Error ? r.message : "Failed to store OAuth state"
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async function N() {
|
|
246
|
-
try {
|
|
247
|
-
const e = await R(A);
|
|
248
|
-
if (!e)
|
|
249
|
-
return null;
|
|
250
|
-
const t = JSON.parse(e);
|
|
251
|
-
return t.expiresAt < Date.now() ? (await d(), null) : (await d(), {
|
|
252
|
-
state: t.state,
|
|
253
|
-
provider: t.provider
|
|
254
|
-
});
|
|
255
|
-
} catch {
|
|
256
|
-
return await d(), null;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
async function d() {
|
|
260
|
-
await f(A, { path: "/" });
|
|
261
|
-
}
|
|
262
|
-
const W = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
263
|
-
__proto__: null,
|
|
264
|
-
deleteOAuthStateCookie: d,
|
|
265
|
-
getOAuthStateCookie: N,
|
|
266
|
-
storeOAuthStateCookie: k
|
|
267
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
268
|
-
export {
|
|
269
|
-
M as a,
|
|
270
|
-
p as b,
|
|
271
|
-
D as c,
|
|
272
|
-
V as d,
|
|
273
|
-
g as e,
|
|
274
|
-
S as f,
|
|
275
|
-
q as g,
|
|
276
|
-
_ as h,
|
|
277
|
-
U as i,
|
|
278
|
-
E as j,
|
|
279
|
-
z as k,
|
|
280
|
-
N as l,
|
|
281
|
-
d as m,
|
|
282
|
-
j as n,
|
|
283
|
-
P as o,
|
|
284
|
-
L as p,
|
|
285
|
-
W as q,
|
|
286
|
-
H as r,
|
|
287
|
-
k as s,
|
|
288
|
-
m as v
|
|
289
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const f=require("./actions-CExpv_dD.js"),C=require("next/navigation"),A=require("next/server");function d(e){return!e||!e.expiresAt?!1:new Date(e.expiresAt)<new Date}function E(e,t=5){if(!e||!e.expiresAt)return!1;const r=new Date(e.expiresAt),s=new Date,i=(r.getTime()-s.getTime())/(1e3*60);return i>0&&i<t}function D(e){if(!e||!e.expiresAt)return null;const t=new Date(e.expiresAt),r=new Date,s=(t.getTime()-r.getTime())/(1e3*60);return s>0?Math.floor(s):0}function N(e){return!(!e||!e.user||!e.user.id||!e.user.email||!e.user.name||d(e))}function S(e){if(!e||typeof e!="object")return!1;const t=e;if(!t.user||typeof t.user!="object")return!1;const r=t.user;if(typeof r.id!="string"||r.id.length===0||typeof r.email!="string"||r.email.length===0||typeof r.name!="string"||r.name.length===0||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r.email))return!1;if(t.expiresAt)if(t.expiresAt instanceof Date){if(isNaN(t.expiresAt.getTime()))return!1}else if(typeof t.expiresAt=="string"){const i=new Date(t.expiresAt);if(isNaN(i.getTime()))return!1}else return!1;return!0}function O(e,t){const r=t.cookieName||"__mulguard_session";let s=null,i=0;const p=6e4;return{async getSession(n){try{if(!await f.getCookie(r))return s=null,null;const a=Date.now();if(s&&a-i<p){if(!(n!=null&&n.skipRefresh)&&this.shouldRefreshSession(s,t)){const o=await this.refreshSession();if(o)return s=o,i=a,o}return s}const c=await e.get("/api/auth/session");if(!c.data.session)return s=null,null;const l=c.data.session;if(!S(l))return await f.deleteCookie(r),s=null,null;if(d(l)){if(!(n!=null&&n.skipRefresh)&&this.shouldRefreshSession(l,t)){const o=await this.refreshSession();if(o)return s=o,i=a,o}return await f.deleteCookie(r),s=null,null}if(!(n!=null&&n.skipRefresh)&&this.shouldRefreshSession(l,t)){const o=await this.refreshSession();if(o)return s=o,i=a,o}return s=l,i=a,l}catch{return await f.deleteCookie(r),s=null,null}},setSession(n,u){},async clearSession(n){await f.deleteCookie(r,{path:n.path}),s=null,i=0},async refreshSession(){try{const n=await e.post("/api/auth/refresh");if(!n.data.session)return s=null,null;const u=n.data.session;return S(u)?(s=u,i=Date.now(),u):(s=null,null)}catch{return s=null,null}},isSessionExpired(n){return d(n)},shouldRefreshSession(n,u){if(!n.expiresAt)return!1;const a=new Date(n.expiresAt),c=new Date,l=a.getTime()-c.getTime(),o=5*60*1e3;return l>0&&l<o}}}async function q(e,t){try{const r=await e.post("/api/auth/refresh");return r.data.session?r.data.session:null}catch{return null}}async function g(e){try{const t=await e.getSession();return!t||!S(t)||d(t)?null:t}catch(t){return console.error("Failed to get server session:",t),null}}async function w(e,t="/login"){const r=await g(e);return r||C.redirect(t),r}async function m(e,t,r="/unauthorized"){const s=await w(e);return(!s.user.roles||!s.user.roles.includes(t))&&C.redirect(r),s}async function _(e){const t=await g(e);return(t==null?void 0:t.user)??null}function M(e,t){return{getSession:()=>g(e),requireAuth:r=>w(e,r),requireRole:(r,s)=>m(e,r,s)}}function U(e){return{getSession:()=>g(e),requireAuth:t=>w(e,t),requireRole:(t,r)=>m(e,t,r),getCurrentUser:()=>_(e)}}function y(e,t=[]){return[...["/auth/login","/auth/register","/auth/forgot-password","/auth/reset-password","/auth/verify-email"],...t].some(i=>e.startsWith(i))}function x(e,t={}){const{redirectTo:r="/auth/login",requireAuth:s=!1,allowedRoles:i=[],publicRoutes:p=[]}=t;return async n=>{const{pathname:u}=n.nextUrl;if(y(u,p)||u.startsWith("/api/")||u.startsWith("/_next/")||u.startsWith("/favicon.ico")||u.match(/\.(ico|png|jpg|jpeg|svg|gif|webp|css|js|woff|woff2|ttf|eot)$/))return null;try{const a=await e.getSession();if(s&&!a){const c=new URL(r,n.url);return c.searchParams.set("redirect",u),A.NextResponse.redirect(c)}if(a&&i.length>0){const c=a.user.roles||[];if(!i.some(o=>c.includes(o)))return A.NextResponse.redirect(new URL("/unauthorized",n.url))}return a&&y(u,p)?A.NextResponse.redirect(new URL("/",n.url)):null}catch(a){return process.env.NODE_ENV==="development"&&console.error("[Mulguard Middleware] Error:",a),null}}}function b(e,t="/auth/login"){return x(e,{requireAuth:!0,redirectTo:t})}function P(e,t,r="/unauthorized"){return x(e,{requireAuth:!0,allowedRoles:t,redirectTo:r})}const R="__mulguard_oauth_state",T=10*60;async function k(e,t){try{const r=JSON.stringify({state:e,provider:t,expiresAt:Date.now()+T*1e3}),s=process.env.NODE_ENV==="production";return await f.setCookie({name:R,value:r,httpOnly:!0,secure:s,sameSite:"strict",maxAge:T,path:"/"})}catch(r){return{success:!1,error:r instanceof Error?r.message:"Failed to store OAuth state"}}}async function v(){try{const e=await f.getCookie(R);if(!e)return null;const t=JSON.parse(e);return t.expiresAt<Date.now()?(await h(),null):(await h(),{state:t.state,provider:t.provider})}catch{return await h(),null}}async function h(){await f.deleteCookie(R,{path:"/"})}const j=Object.freeze(Object.defineProperty({__proto__:null,deleteOAuthStateCookie:h,getOAuthStateCookie:v,storeOAuthStateCookie:k},Symbol.toStringTag,{value:"Module"}));exports.createAuthMiddleware=x;exports.createServerHelpers=M;exports.createServerUtils=U;exports.createSessionManager=O;exports.deleteOAuthStateCookie=h;exports.getCurrentUser=_;exports.getOAuthStateCookie=v;exports.getServerSession=g;exports.getSessionTimeUntilExpiry=D;exports.isSessionExpiredNullable=d;exports.isSessionExpiringSoon=E;exports.isSessionValid=N;exports.oauthState=j;exports.refreshSession=q;exports.requireAuth=w;exports.requireAuthMiddleware=b;exports.requireRole=m;exports.requireRoleMiddleware=P;exports.storeOAuthStateCookie=k;exports.validateSessionStructure=S;
|
package/dist/server/actions.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { MulguardInstance } from '../mulguard';
|
|
2
|
-
import { Verify2FAData, AuthResult, EmailCredentials, RegisterData } from '../core/types';
|
|
3
|
-
/**
|
|
4
|
-
* Verify 2FA code - Server Action
|
|
5
|
-
*
|
|
6
|
-
* ✅ Works in all scenarios:
|
|
7
|
-
* - Direct import in client components
|
|
8
|
-
* - Wrapped in separate files with 'use server'
|
|
9
|
-
* - Automatic CSRF protection and cookie handling
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Option 1: Direct use in client component
|
|
14
|
-
* 'use client'
|
|
15
|
-
* import { verify2FAAction } from 'mulguard/server'
|
|
16
|
-
* import { auth } from '@/lib/auth'
|
|
17
|
-
*
|
|
18
|
-
* const result = await verify2FAAction(auth, { email, userId, code })
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // Option 2: Wrap in separate file
|
|
24
|
-
* // lib/auth-actions.ts
|
|
25
|
-
* 'use server'
|
|
26
|
-
* import { verify2FAAction as baseVerify2FA } from 'mulguard/server'
|
|
27
|
-
* import { auth } from './auth'
|
|
28
|
-
*
|
|
29
|
-
* export async function verify2FA(data: Verify2FAData) {
|
|
30
|
-
* return await baseVerify2FA(auth, data)
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* // Then use in client component:
|
|
34
|
-
* 'use client'
|
|
35
|
-
* import { verify2FA } from '@/lib/auth-actions'
|
|
36
|
-
* const result = await verify2FA({ email, userId, code })
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function verify2FAAction(auth: MulguardInstance, data: Verify2FAData): Promise<AuthResult>;
|
|
40
|
-
/**
|
|
41
|
-
* Sign out - Server Action
|
|
42
|
-
*
|
|
43
|
-
* ✅ Works in all scenarios:
|
|
44
|
-
* - Direct import in client components
|
|
45
|
-
* - Wrapped in separate files with 'use server'
|
|
46
|
-
* - Automatic cookie clearing
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // Option 1: Direct use in client component
|
|
51
|
-
* 'use client'
|
|
52
|
-
* import { signOutAction } from 'mulguard/server'
|
|
53
|
-
* import { auth } from '@/lib/auth'
|
|
54
|
-
*
|
|
55
|
-
* await signOutAction(auth)
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* // Option 2: Wrap in separate file
|
|
61
|
-
* // lib/auth-actions.ts
|
|
62
|
-
* 'use server'
|
|
63
|
-
* import { signOutAction as baseSignOut } from 'mulguard/server'
|
|
64
|
-
* import { auth } from './auth'
|
|
65
|
-
*
|
|
66
|
-
* export async function signOut() {
|
|
67
|
-
* return await baseSignOut(auth)
|
|
68
|
-
* }
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function signOutAction(auth: MulguardInstance): Promise<{
|
|
72
|
-
success: boolean;
|
|
73
|
-
error?: string;
|
|
74
|
-
}>;
|
|
75
|
-
/**
|
|
76
|
-
* Sign in with email - Server Action
|
|
77
|
-
*
|
|
78
|
-
* ✅ Works in all scenarios
|
|
79
|
-
*/
|
|
80
|
-
export declare function signInEmailAction(auth: MulguardInstance, credentials: EmailCredentials): Promise<AuthResult>;
|
|
81
|
-
/**
|
|
82
|
-
* Sign up - Server Action
|
|
83
|
-
*
|
|
84
|
-
* ✅ Works in all scenarios
|
|
85
|
-
*/
|
|
86
|
-
export declare function signUpAction(auth: MulguardInstance, data: RegisterData): Promise<AuthResult>;
|
package/dist/server/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MulguardInstance } from '../mulguard';
|
|
2
|
-
import { MulguardConfig } from '../core/types';
|
|
3
|
-
/**
|
|
4
|
-
* Create server-side auth helpers with pre-configured instance
|
|
5
|
-
*/
|
|
6
|
-
export declare function createServerHelpers(_auth: MulguardInstance, _config: MulguardConfig): {
|
|
7
|
-
getSession: () => Promise<import('..').Session<import('..').User> | null>;
|
|
8
|
-
requireAuth: (redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
9
|
-
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
10
|
-
};
|
package/dist/server/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side utilities for Next.js
|
|
3
|
-
*/
|
|
4
|
-
export * from './cookies';
|
|
5
|
-
export * from './session';
|
|
6
|
-
export * from './auth';
|
|
7
|
-
export * from './helpers';
|
|
8
|
-
export * from './utils';
|
|
9
|
-
export { isSessionExpiringSoon, getSessionTimeUntilExpiry, isSessionValid, validateSessionStructure, isSessionExpiredNullable, } from './session-helpers';
|
|
10
|
-
export { createAuthMiddleware as createServerAuthMiddleware, requireAuthMiddleware as requireServerAuthMiddleware, requireRoleMiddleware as requireServerRoleMiddleware, } from './middleware';
|
|
11
|
-
export { getServerSession, requireAuth, requireRole, getCurrentUser } from './auth';
|
|
12
|
-
export { createServerUtils } from './utils';
|
|
13
|
-
export { verify2FAAction, signOutAction, signInEmailAction, signUpAction, } from './actions';
|
|
14
|
-
export { storeOAuthStateCookie, getOAuthStateCookie, deleteOAuthStateCookie, } from './oauth-state';
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { MulguardInstance } from '../mulguard';
|
|
3
|
-
export interface AuthMiddlewareOptions {
|
|
4
|
-
/** Redirect to this URL if authentication is required but user is not authenticated */
|
|
5
|
-
redirectTo?: string;
|
|
6
|
-
/** Require authentication for all routes */
|
|
7
|
-
requireAuth?: boolean;
|
|
8
|
-
/** Require specific roles */
|
|
9
|
-
allowedRoles?: string[];
|
|
10
|
-
/** Public routes that don't require authentication */
|
|
11
|
-
publicRoutes?: string[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create authentication middleware for Next.js
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // middleware.ts
|
|
19
|
-
* import { auth } from '@/lib/auth'
|
|
20
|
-
* import { createAuthMiddleware } from 'mulguard/server'
|
|
21
|
-
*
|
|
22
|
-
* export const middleware = createAuthMiddleware(auth, {
|
|
23
|
-
* requireAuth: true,
|
|
24
|
-
* redirectTo: '/auth/login',
|
|
25
|
-
* allowedRoles: ['admin'],
|
|
26
|
-
* })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function createAuthMiddleware(auth: MulguardInstance, options?: AuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Require authentication middleware
|
|
32
|
-
* Shortcut for createAuthMiddleware with requireAuth: true
|
|
33
|
-
*/
|
|
34
|
-
export declare function requireAuthMiddleware(auth: MulguardInstance, redirectTo?: string): (request: NextRequest) => Promise<NextResponse | null>;
|
|
35
|
-
/**
|
|
36
|
-
* Require role middleware
|
|
37
|
-
* Shortcut for createAuthMiddleware with allowedRoles
|
|
38
|
-
*/
|
|
39
|
-
export declare function requireRoleMiddleware(auth: MulguardInstance, roles: string[], redirectTo?: string): (request: NextRequest) => Promise<NextResponse | null>;
|
package/dist/server/session.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Session, SessionConfig } from '../core/types';
|
|
2
|
-
type ApiClient = {
|
|
3
|
-
get: <T>(url: string) => Promise<{
|
|
4
|
-
data: T;
|
|
5
|
-
}>;
|
|
6
|
-
post: <T>(url: string, data?: unknown) => Promise<{
|
|
7
|
-
data: T;
|
|
8
|
-
}>;
|
|
9
|
-
};
|
|
10
|
-
export interface SessionManager {
|
|
11
|
-
getSession(options?: {
|
|
12
|
-
skipRefresh?: boolean;
|
|
13
|
-
}): Promise<Session | null>;
|
|
14
|
-
setSession(session: Session, config: SessionConfig): void;
|
|
15
|
-
clearSession(config: SessionConfig): Promise<void>;
|
|
16
|
-
refreshSession(): Promise<Session | null>;
|
|
17
|
-
isSessionExpired(session: Session): boolean;
|
|
18
|
-
shouldRefreshSession(session: Session, config: SessionConfig): boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create session manager with automatic refresh
|
|
22
|
-
*/
|
|
23
|
-
export declare function createSessionManager(client: ApiClient, config: SessionConfig): SessionManager;
|
|
24
|
-
/**
|
|
25
|
-
* Refresh session
|
|
26
|
-
*/
|
|
27
|
-
export declare function refreshSession(client: ApiClient, _config: SessionConfig): Promise<Session | null>;
|
|
28
|
-
export {};
|
package/dist/server/utils.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MulguardInstance } from '../mulguard';
|
|
2
|
-
/**
|
|
3
|
-
* Create server-side helpers with pre-configured auth instance
|
|
4
|
-
*/
|
|
5
|
-
export declare function createServerUtils(auth: MulguardInstance): {
|
|
6
|
-
getSession: () => Promise<import('..').Session<import('..').User> | null>;
|
|
7
|
-
requireAuth: (redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
8
|
-
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
9
|
-
getCurrentUser: () => Promise<import('..').User | null>;
|
|
10
|
-
};
|
|
File without changes
|