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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var A = Object.defineProperty;
|
|
2
|
+
var S = (t, e, r) => e in t ? A(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var i = (t, e, r) => S(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { A as x, f as w, c as m, g as y, d as E } from "./actions-CjQUKaXF.mjs";
|
|
5
|
+
import { redirect as p } from "next/navigation";
|
|
6
|
+
class o extends Error {
|
|
7
|
+
constructor(r, s, n, g) {
|
|
8
|
+
super(s);
|
|
9
|
+
i(this, "code");
|
|
10
|
+
i(this, "statusCode");
|
|
11
|
+
i(this, "details");
|
|
12
|
+
this.name = "AuthError", this.code = r, this.statusCode = n ?? w(r), this.details = g, Error.captureStackTrace && Error.captureStackTrace(this, o);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts error to plain object for serialization.
|
|
16
|
+
*
|
|
17
|
+
* @returns Plain error object
|
|
18
|
+
*/
|
|
19
|
+
toJSON() {
|
|
20
|
+
return {
|
|
21
|
+
code: this.code,
|
|
22
|
+
message: this.message,
|
|
23
|
+
statusCode: this.statusCode,
|
|
24
|
+
details: this.details
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates error result for failed operations.
|
|
29
|
+
*
|
|
30
|
+
* @returns ErrorResult object
|
|
31
|
+
*/
|
|
32
|
+
toErrorResult() {
|
|
33
|
+
return {
|
|
34
|
+
success: !1,
|
|
35
|
+
error: this.message,
|
|
36
|
+
errorCode: this.code,
|
|
37
|
+
details: this.details
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class l extends o {
|
|
42
|
+
constructor(e = "Session has expired", r) {
|
|
43
|
+
super(x.SESSION_EXPIRED, e, void 0, r), this.name = "SessionExpiredError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function d(t) {
|
|
47
|
+
return !t || !t.expiresAt ? !1 : new Date(t.expiresAt) < /* @__PURE__ */ new Date();
|
|
48
|
+
}
|
|
49
|
+
function k(t, e = 5) {
|
|
50
|
+
if (!t || !t.expiresAt)
|
|
51
|
+
return !1;
|
|
52
|
+
const r = new Date(t.expiresAt), s = /* @__PURE__ */ new Date(), n = (r.getTime() - s.getTime()) / (1e3 * 60);
|
|
53
|
+
return n > 0 && n < e;
|
|
54
|
+
}
|
|
55
|
+
function b(t) {
|
|
56
|
+
if (!t || !t.expiresAt)
|
|
57
|
+
return null;
|
|
58
|
+
const e = new Date(t.expiresAt), r = /* @__PURE__ */ new Date(), s = (e.getTime() - r.getTime()) / (1e3 * 60);
|
|
59
|
+
return s > 0 ? Math.floor(s) : 0;
|
|
60
|
+
}
|
|
61
|
+
function j(t) {
|
|
62
|
+
return !(!t || !t.user || !t.user.id || !t.user.email || !t.user.name || d(t));
|
|
63
|
+
}
|
|
64
|
+
function T(t) {
|
|
65
|
+
if (!t || typeof t != "object")
|
|
66
|
+
return !1;
|
|
67
|
+
const e = t;
|
|
68
|
+
if (!e.user || typeof e.user != "object")
|
|
69
|
+
return !1;
|
|
70
|
+
const r = e.user;
|
|
71
|
+
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))
|
|
72
|
+
return !1;
|
|
73
|
+
if (e.expiresAt)
|
|
74
|
+
if (e.expiresAt instanceof Date) {
|
|
75
|
+
if (isNaN(e.expiresAt.getTime()))
|
|
76
|
+
return !1;
|
|
77
|
+
} else if (typeof e.expiresAt == "string") {
|
|
78
|
+
const n = new Date(e.expiresAt);
|
|
79
|
+
if (isNaN(n.getTime()))
|
|
80
|
+
return !1;
|
|
81
|
+
} else
|
|
82
|
+
return !1;
|
|
83
|
+
return !0;
|
|
84
|
+
}
|
|
85
|
+
async function u(t) {
|
|
86
|
+
try {
|
|
87
|
+
const e = await t.getSession();
|
|
88
|
+
if (!e)
|
|
89
|
+
return null;
|
|
90
|
+
if ((typeof e.expiresAt == "string" ? new Date(e.expiresAt) : e.expiresAt).getTime() < Date.now())
|
|
91
|
+
throw new l("Session has expired");
|
|
92
|
+
return e;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
if (e instanceof l)
|
|
95
|
+
throw e;
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function M(t) {
|
|
100
|
+
try {
|
|
101
|
+
return await u(t) !== null;
|
|
102
|
+
} catch {
|
|
103
|
+
return !1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function R(t) {
|
|
107
|
+
const e = await u(t);
|
|
108
|
+
return (e == null ? void 0 : e.user) || null;
|
|
109
|
+
}
|
|
110
|
+
function U(t) {
|
|
111
|
+
return async () => {
|
|
112
|
+
try {
|
|
113
|
+
return await t();
|
|
114
|
+
} catch (e) {
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function V(t, e) {
|
|
120
|
+
return async () => {
|
|
121
|
+
const r = await u(t);
|
|
122
|
+
if (!r)
|
|
123
|
+
throw new Error("Authentication required");
|
|
124
|
+
return await e(r.user);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function h(t) {
|
|
128
|
+
try {
|
|
129
|
+
const e = await t.getSession();
|
|
130
|
+
return !e || !T(e) || d(e) ? null : e;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return process.env.NODE_ENV === "development" && console.error("Failed to get server session:", e), null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function D(t, e = "/login") {
|
|
136
|
+
const r = await h(t);
|
|
137
|
+
return r || p(e), r;
|
|
138
|
+
}
|
|
139
|
+
async function q(t, e, r = "/unauthorized") {
|
|
140
|
+
const s = await D(t);
|
|
141
|
+
return (!s.user.roles || !s.user.roles.includes(e)) && p(r), s;
|
|
142
|
+
}
|
|
143
|
+
async function I(t) {
|
|
144
|
+
const e = await h(t);
|
|
145
|
+
return (e == null ? void 0 : e.user) ?? null;
|
|
146
|
+
}
|
|
147
|
+
const c = "__mulguard_oauth_state", f = 10 * 60;
|
|
148
|
+
async function O(t, e) {
|
|
149
|
+
try {
|
|
150
|
+
const r = JSON.stringify({ state: t, provider: e, expiresAt: Date.now() + f * 1e3 }), s = process.env.NODE_ENV === "production";
|
|
151
|
+
return await m({
|
|
152
|
+
name: c,
|
|
153
|
+
value: r,
|
|
154
|
+
httpOnly: !0,
|
|
155
|
+
secure: s,
|
|
156
|
+
sameSite: "lax",
|
|
157
|
+
// Changed from 'strict' to 'lax' to allow cookie in OAuth redirect flow
|
|
158
|
+
maxAge: f,
|
|
159
|
+
path: "/"
|
|
160
|
+
});
|
|
161
|
+
} catch (r) {
|
|
162
|
+
return {
|
|
163
|
+
success: !1,
|
|
164
|
+
error: r instanceof Error ? r.message : "Failed to store OAuth state"
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function v() {
|
|
169
|
+
try {
|
|
170
|
+
const t = await y(c);
|
|
171
|
+
if (!t)
|
|
172
|
+
return null;
|
|
173
|
+
const e = JSON.parse(t);
|
|
174
|
+
return e.expiresAt < Date.now() ? (await a(), null) : (await a(), {
|
|
175
|
+
state: e.state,
|
|
176
|
+
provider: e.provider
|
|
177
|
+
});
|
|
178
|
+
} catch {
|
|
179
|
+
return await a(), null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function a() {
|
|
183
|
+
await E(c, { path: "/" });
|
|
184
|
+
}
|
|
185
|
+
const J = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
186
|
+
__proto__: null,
|
|
187
|
+
deleteOAuthStateCookie: a,
|
|
188
|
+
getOAuthStateCookie: v,
|
|
189
|
+
storeOAuthStateCookie: O
|
|
190
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
191
|
+
export {
|
|
192
|
+
l as S,
|
|
193
|
+
q as a,
|
|
194
|
+
u as b,
|
|
195
|
+
R as c,
|
|
196
|
+
U as d,
|
|
197
|
+
V as e,
|
|
198
|
+
d as f,
|
|
199
|
+
I as g,
|
|
200
|
+
k as h,
|
|
201
|
+
M as i,
|
|
202
|
+
b as j,
|
|
203
|
+
j as k,
|
|
204
|
+
v as l,
|
|
205
|
+
a as m,
|
|
206
|
+
J as o,
|
|
207
|
+
D as r,
|
|
208
|
+
O as s,
|
|
209
|
+
T as v
|
|
210
|
+
};
|
package/dist/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../oauth-state-Drwz6fES.js"),i=require("../actions-CMtg7FGv.js");exports.SessionExpiredError=e.SessionExpiredError;exports.createAuthenticatedAction=e.createAuthenticatedAction;exports.createServerAction=e.createServerAction;exports.deleteOAuthStateCookie=e.deleteOAuthStateCookie;exports.getCurrentUser=e.getCurrentUser;exports.getOAuthStateCookie=e.getOAuthStateCookie;exports.getServerSession=e.getServerSession;exports.getServerUser=e.getServerUser;exports.getSessionTimeUntilExpiry=e.getSessionTimeUntilExpiry;exports.isAuthenticated=e.isAuthenticated;exports.isSessionExpiredNullable=e.isSessionExpiredNullable;exports.isSessionExpiringSoon=e.isSessionExpiringSoon;exports.isSessionValid=e.isSessionValid;exports.requireAuth=e.requireAuth;exports.requireRole=e.requireRole;exports.storeOAuthStateCookie=e.storeOAuthStateCookie;exports.validateSessionStructure=e.validateSessionStructure;exports.buildCookieOptions=i.buildCookieOptions;exports.deleteCookie=i.deleteCookie;exports.getCookie=i.getCookie;exports.setCookie=i.setCookie;exports.signInEmailAction=i.signInEmailAction;exports.signOutAction=i.signOutAction;exports.signUpAction=i.signUpAction;exports.verify2FAAction=i.verify2FAAction;
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import { e as
|
|
2
|
-
import {
|
|
1
|
+
import { S as i, e as t, d as a, m as o, g as r, l as n, b as S, c as u, j as c, i as A, f as g, h as l, k as d, r as k, a as p, s as C, v as h } from "../oauth-state-pdypStuS.mjs";
|
|
2
|
+
import { e as x, d as E, g as m, c as O, a as b, s as f, b as U, v as q } from "../actions-CjQUKaXF.mjs";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
r as
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
w as validateSessionStructure,
|
|
30
|
-
l as verify2FAAction
|
|
4
|
+
i as SessionExpiredError,
|
|
5
|
+
x as buildCookieOptions,
|
|
6
|
+
t as createAuthenticatedAction,
|
|
7
|
+
a as createServerAction,
|
|
8
|
+
E as deleteCookie,
|
|
9
|
+
o as deleteOAuthStateCookie,
|
|
10
|
+
m as getCookie,
|
|
11
|
+
r as getCurrentUser,
|
|
12
|
+
n as getOAuthStateCookie,
|
|
13
|
+
S as getServerSession,
|
|
14
|
+
u as getServerUser,
|
|
15
|
+
c as getSessionTimeUntilExpiry,
|
|
16
|
+
A as isAuthenticated,
|
|
17
|
+
g as isSessionExpiredNullable,
|
|
18
|
+
l as isSessionExpiringSoon,
|
|
19
|
+
d as isSessionValid,
|
|
20
|
+
k as requireAuth,
|
|
21
|
+
p as requireRole,
|
|
22
|
+
O as setCookie,
|
|
23
|
+
b as signInEmailAction,
|
|
24
|
+
f as signOutAction,
|
|
25
|
+
U as signUpAction,
|
|
26
|
+
C as storeOAuthStateCookie,
|
|
27
|
+
h as validateSessionStructure,
|
|
28
|
+
q as verify2FAAction
|
|
31
29
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mulguard",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "A modern, stable authentication library for Next.js 16+ (App Router) - مكتبة مصادقة حديثة ومستقرة لـ Next.js",
|
|
5
5
|
"main": "./dist/index/index.js",
|
|
6
6
|
"module": "./dist/index/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -20,10 +20,23 @@
|
|
|
20
20
|
"types": "./dist/client/index.d.ts",
|
|
21
21
|
"import": "./dist/client/index.mjs",
|
|
22
22
|
"require": "./dist/client/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./proxy": {
|
|
25
|
+
"types": "./dist/proxy/index.d.ts",
|
|
26
|
+
"import": "./dist/proxy/index.mjs",
|
|
27
|
+
"require": "./dist/proxy/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./handlers": {
|
|
30
|
+
"types": "./dist/handlers/index.d.ts",
|
|
31
|
+
"import": "./dist/handlers/index.mjs",
|
|
32
|
+
"require": "./dist/handlers/index.js"
|
|
23
33
|
}
|
|
24
34
|
},
|
|
25
35
|
"files": [
|
|
26
|
-
"dist"
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"ARCHITECTURE.md",
|
|
39
|
+
"API_DESIGN.md"
|
|
27
40
|
],
|
|
28
41
|
"scripts": {
|
|
29
42
|
"build": "vite build",
|
|
@@ -36,21 +49,43 @@
|
|
|
36
49
|
"prepublishOnly": "npm run build",
|
|
37
50
|
"changeset": "changeset add",
|
|
38
51
|
"version": "changeset version",
|
|
39
|
-
"release": "changeset version && npm run build && changeset publish"
|
|
52
|
+
"release": "changeset version && npm run build && changeset publish",
|
|
53
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
54
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
40
55
|
},
|
|
41
56
|
"keywords": [
|
|
42
57
|
"nextjs",
|
|
58
|
+
"next.js",
|
|
59
|
+
"nextjs-16",
|
|
43
60
|
"mulguard",
|
|
44
|
-
"mulink",
|
|
45
|
-
"mukey",
|
|
46
61
|
"mulverse",
|
|
47
|
-
"MxHabob",
|
|
48
62
|
"authentication",
|
|
49
63
|
"auth",
|
|
50
|
-
"
|
|
64
|
+
"oauth",
|
|
65
|
+
"oauth2",
|
|
66
|
+
"pkce",
|
|
67
|
+
"session",
|
|
68
|
+
"middleware",
|
|
69
|
+
"server-actions",
|
|
70
|
+
"typescript",
|
|
71
|
+
"edge-runtime",
|
|
72
|
+
"security",
|
|
73
|
+
"mfa",
|
|
74
|
+
"2fa",
|
|
75
|
+
"otp",
|
|
76
|
+
"passkey",
|
|
77
|
+
"webauthn"
|
|
51
78
|
],
|
|
52
|
-
"author": "
|
|
53
|
-
"license": "MUV
|
|
79
|
+
"author": "Mulverse Team",
|
|
80
|
+
"license": "MUV",
|
|
81
|
+
"repository": {
|
|
82
|
+
"type": "git",
|
|
83
|
+
"url": "https://github.com/mulverse/mulguard.git"
|
|
84
|
+
},
|
|
85
|
+
"bugs": {
|
|
86
|
+
"url": "https://github.com/mulverse/mulguard/issues"
|
|
87
|
+
},
|
|
88
|
+
"homepage": "https://github.com/mulverse/mulguard#readme",
|
|
54
89
|
"dependencies": {
|
|
55
90
|
"@noble/hashes": "^1.3.3"
|
|
56
91
|
},
|
|
@@ -58,6 +93,10 @@
|
|
|
58
93
|
"@changesets/cli": "^2.27.1",
|
|
59
94
|
"@types/node": "^20.11.5",
|
|
60
95
|
"@types/react": "^18.2.48",
|
|
96
|
+
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
97
|
+
"@typescript-eslint/parser": "^8.50.0",
|
|
98
|
+
"eslint": "^8.57.1",
|
|
99
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
100
|
"next": "^16.0.10",
|
|
62
101
|
"turbo": "^2.0.0",
|
|
63
102
|
"typescript": "^5.3.3",
|
|
@@ -66,8 +105,22 @@
|
|
|
66
105
|
"vitest": "^1.2.0"
|
|
67
106
|
},
|
|
68
107
|
"peerDependencies": {
|
|
69
|
-
"next": ">=
|
|
108
|
+
"next": ">=16.0.0",
|
|
70
109
|
"react": ">=18.0.0 || ^19.0.0",
|
|
71
110
|
"react-dom": ">=18.0.0 || ^19.0.0"
|
|
111
|
+
},
|
|
112
|
+
"peerDependenciesMeta": {
|
|
113
|
+
"react": {
|
|
114
|
+
"optional": false
|
|
115
|
+
},
|
|
116
|
+
"react-dom": {
|
|
117
|
+
"optional": false
|
|
118
|
+
},
|
|
119
|
+
"next": {
|
|
120
|
+
"optional": false
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"engines": {
|
|
124
|
+
"node": ">=18.0.0"
|
|
72
125
|
}
|
|
73
126
|
}
|
package/dist/actions-CExpv_dD.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const O=require("next/headers");var r=(s=>(s.INVALID_CREDENTIALS="INVALID_CREDENTIALS",s.ACCOUNT_LOCKED="ACCOUNT_LOCKED",s.ACCOUNT_INACTIVE="ACCOUNT_INACTIVE",s.TWO_FA_REQUIRED="TWO_FA_REQUIRED",s.INVALID_TWO_FA_CODE="INVALID_TWO_FA_CODE",s.SESSION_EXPIRED="SESSION_EXPIRED",s.UNAUTHORIZED="UNAUTHORIZED",s.NETWORK_ERROR="NETWORK_ERROR",s.VALIDATION_ERROR="VALIDATION_ERROR",s.RATE_LIMITED="RATE_LIMITED",s.UNKNOWN_ERROR="UNKNOWN_ERROR",s))(r||{});async function R(s){var n;try{return(n=(await O.cookies()).get(s))==null?void 0:n.value}catch(e){const o=(e==null?void 0:e.message)||"";if(o.includes("cookies")||o.includes("request scope")||o.includes("outside")||o.includes("dynamic"))return;throw e}}async function u(s){try{return(await O.cookies()).set({name:s.name,value:s.value,maxAge:s.maxAge,expires:s.expires,httpOnly:s.httpOnly??!0,secure:s.secure,sameSite:s.sameSite??"lax",path:s.path??"/",domain:s.domain}),{success:!0}}catch(n){const e=(n==null?void 0:n.message)||"";if(e.includes("cookies")||e.includes("request scope")||e.includes("outside")||e.includes("dynamic")){const o=`Cannot set cookie "${s.name}" outside request scope. Make sure this is called from a Server Action or Route Handler.`;return process.env.NODE_ENV==="development"&&console.warn(`[Mulguard] ${o}`),{success:!1,error:e,warning:o}}throw n}}async function f(s,n){try{(await O.cookies()).set({name:s,value:"",maxAge:0,expires:new Date(0),httpOnly:!0,path:(n==null?void 0:n.path)??"/",domain:n==null?void 0:n.domain})}catch(e){const o=(e==null?void 0:e.message)||"";if(o.includes("cookies")||o.includes("request scope")||o.includes("outside")||o.includes("dynamic")){process.env.NODE_ENV==="development"&&console.warn(`[Mulguard] Cannot delete cookie "${s}" outside request scope`);return}throw e}}function l(s,n,e){const o=process.env.NODE_ENV==="production";return{name:s,value:n,maxAge:e.expiresIn,httpOnly:e.httpOnly??!0,secure:e.secure??o,sameSite:e.sameSite??"lax",path:e.path??"/"}}async function g(s,n){if(!s.verify2FA)return{success:!1,error:"2FA verification is not configured",errorCode:r.VALIDATION_ERROR};try{const e=await s.verify2FA(n,{skipCookieSave:!0});if(e.success&&e.session)try{const{cookieName:o,config:t}=s._getSessionConfig(),c=typeof e.session=="object"&&"token"in e.session?String(e.session.token):JSON.stringify(e.session),i=l(o,c,t),a=await u(i);a.success||process.env.NODE_ENV==="development"&&console.warn("[Mulguard] Failed to save session after 2FA verification:",a.error||a.warning)}catch(o){process.env.NODE_ENV==="development"&&console.warn("[Mulguard] Failed to save session cookie:",o)}return e}catch(e){return{success:!1,error:e instanceof Error?e.message:"2FA verification failed",errorCode:r.UNKNOWN_ERROR}}}async function N(s){var n;try{const e=await s.getSession(),o=e==null?void 0:e.user;s.signOut&&await s.signOut();const{cookieName:t,config:c}=s._getSessionConfig();await f(t,{path:c.path||"/"});const i=(n=s._getCallbacks)==null?void 0:n.call(s);return o&&(i!=null&&i.onSignOut)&&await i.onSignOut(o),{success:!0}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Sign out failed"}}}async function d(s,n){var e;if(!((e=s.signIn)!=null&&e.email))return{success:!1,error:"Email sign in is not configured",errorCode:r.VALIDATION_ERROR};try{const o=await s.signIn.email(n);if(o.success&&o.session)try{const{cookieName:t,config:c}=s._getSessionConfig(),i=typeof o.session=="object"&&"token"in o.session?String(o.session.token):JSON.stringify(o.session),a=l(t,i,c);await u(a)}catch(t){process.env.NODE_ENV==="development"&&console.warn("[Mulguard] Failed to save session cookie:",t)}return o}catch(o){return{success:!1,error:o instanceof Error?o.message:"Sign in failed",errorCode:r.UNKNOWN_ERROR}}}async function E(s,n){if(!s.signUp)return{success:!1,error:"Sign up is not configured",errorCode:r.VALIDATION_ERROR};try{const e=await s.signUp(n);if(e.success&&e.session)try{const{cookieName:o,config:t}=s._getSessionConfig(),c=typeof e.session=="object"&&"token"in e.session?String(e.session.token):JSON.stringify(e.session),i=l(o,c,t);await u(i)}catch(o){process.env.NODE_ENV==="development"&&console.warn("[Mulguard] Failed to save session cookie:",o)}return e}catch(e){return{success:!1,error:e instanceof Error?e.message:"Sign up failed",errorCode:r.UNKNOWN_ERROR}}}const _=Object.freeze(Object.defineProperty({__proto__:null,signInEmailAction:d,signOutAction:N,signUpAction:E,verify2FAAction:g},Symbol.toStringTag,{value:"Module"}));exports.AuthErrorCode=r;exports.actions=_;exports.buildCookieOptions=l;exports.deleteCookie=f;exports.getCookie=R;exports.setCookie=u;exports.signInEmailAction=d;exports.signOutAction=N;exports.signUpAction=E;exports.verify2FAAction=g;
|
package/dist/client/index.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { EmailCredentials, RegisterData, AuthResult, ApiClient } from '../types';
|
|
2
|
-
import { OAuthMethods } from './oauth';
|
|
3
|
-
import { PassKeyMethods } from './passkey';
|
|
4
|
-
import { TwoFactorMethods } from './two-factor';
|
|
5
|
-
import { AccountPickerMethods } from '../account-picker';
|
|
6
|
-
export interface AuthMethods {
|
|
7
|
-
signIn: {
|
|
8
|
-
email(credentials: EmailCredentials): Promise<AuthResult>;
|
|
9
|
-
oauth(provider: string): Promise<{
|
|
10
|
-
url: string;
|
|
11
|
-
state: string;
|
|
12
|
-
}>;
|
|
13
|
-
passkey(options?: {
|
|
14
|
-
userId?: string;
|
|
15
|
-
}): Promise<AuthResult>;
|
|
16
|
-
};
|
|
17
|
-
signUp(data: RegisterData): Promise<AuthResult>;
|
|
18
|
-
signOut(): Promise<void>;
|
|
19
|
-
resetPassword(email: string): Promise<{
|
|
20
|
-
success: boolean;
|
|
21
|
-
error?: string;
|
|
22
|
-
}>;
|
|
23
|
-
verifyEmail(token: string): Promise<{
|
|
24
|
-
success: boolean;
|
|
25
|
-
error?: string;
|
|
26
|
-
}>;
|
|
27
|
-
oauth: OAuthMethods;
|
|
28
|
-
passkey: PassKeyMethods;
|
|
29
|
-
twoFactor: TwoFactorMethods;
|
|
30
|
-
accountPicker: AccountPickerMethods;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create authentication methods
|
|
34
|
-
*/
|
|
35
|
-
export declare function createAuthMethods(client: ApiClient, oauthProviders?: Record<string, {
|
|
36
|
-
clientId: string;
|
|
37
|
-
redirectUri: string;
|
|
38
|
-
scopes?: string[];
|
|
39
|
-
name?: string;
|
|
40
|
-
}>, accountPickerConfig?: import('../account-picker').AccountPickerConfig): AuthMethods;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApiClient, AuthResult } from '../types';
|
|
2
|
-
export interface OAuthProvider {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
clientId: string;
|
|
6
|
-
redirectUri: string;
|
|
7
|
-
scopes?: string[];
|
|
8
|
-
}
|
|
9
|
-
export interface OAuthMethods {
|
|
10
|
-
initiate(provider: string): Promise<{
|
|
11
|
-
url: string;
|
|
12
|
-
state: string;
|
|
13
|
-
}>;
|
|
14
|
-
handleCallback(provider: string, code: string, state: string): Promise<AuthResult>;
|
|
15
|
-
getProviders(): Promise<OAuthProvider[]>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create OAuth methods
|
|
19
|
-
*/
|
|
20
|
-
export declare function createOAuthMethods(client: ApiClient, providers: Record<string, OAuthProvider>): OAuthMethods;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { MulguardInstance } from '../mulguard';
|
|
3
|
-
export interface AuthMiddlewareConfig {
|
|
4
|
-
/**
|
|
5
|
-
* Protected routes - require authentication
|
|
6
|
-
*/
|
|
7
|
-
protectedRoutes?: string[];
|
|
8
|
-
/**
|
|
9
|
-
* Public routes - accessible without authentication
|
|
10
|
-
*/
|
|
11
|
-
publicRoutes?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Redirect to login if not authenticated
|
|
14
|
-
*/
|
|
15
|
-
redirectTo?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Redirect to home if authenticated (for login/register pages)
|
|
18
|
-
*/
|
|
19
|
-
redirectIfAuthenticated?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Create authentication middleware
|
|
23
|
-
*/
|
|
24
|
-
export declare function createAuthMiddleware(auth: MulguardInstance, config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
25
|
-
/**
|
|
26
|
-
* Helper to check if user has required role
|
|
27
|
-
*/
|
|
28
|
-
export declare function checkRole(auth: MulguardInstance, requiredRole: string): Promise<boolean>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { MulguardInstance } from '../mulguard';
|
|
3
|
-
export interface ProxyMiddlewareConfig {
|
|
4
|
-
/**
|
|
5
|
-
* Auth instance
|
|
6
|
-
*/
|
|
7
|
-
auth: MulguardInstance;
|
|
8
|
-
/**
|
|
9
|
-
* Protected routes - require authentication
|
|
10
|
-
*/
|
|
11
|
-
protectedRoutes?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Public routes - accessible without authentication
|
|
14
|
-
*/
|
|
15
|
-
publicRoutes?: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Redirect to login if not authenticated
|
|
18
|
-
*/
|
|
19
|
-
redirectTo?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Redirect to home if authenticated (for login/register pages)
|
|
22
|
-
*/
|
|
23
|
-
redirectIfAuthenticated?: string;
|
|
24
|
-
/**
|
|
25
|
-
* API routes prefix (default: '/api/auth')
|
|
26
|
-
*/
|
|
27
|
-
apiPrefix?: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Create proxy middleware for authentication
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // middleware.ts
|
|
35
|
-
* import { auth } from '@/auth'
|
|
36
|
-
* import { createProxyMiddleware } from 'mulguard/middleware/proxy'
|
|
37
|
-
*
|
|
38
|
-
* export default createProxyMiddleware({
|
|
39
|
-
* auth,
|
|
40
|
-
* protectedRoutes: ['/dashboard', '/profile'],
|
|
41
|
-
* redirectTo: '/login',
|
|
42
|
-
* })
|
|
43
|
-
*
|
|
44
|
-
* export const config = {
|
|
45
|
-
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function createProxyMiddleware(config: ProxyMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
50
|
-
/**
|
|
51
|
-
* Helper to check if user has required role
|
|
52
|
-
*/
|
|
53
|
-
export declare function checkRole(auth: MulguardInstance, requiredRole: string): Promise<boolean>;
|