@voltro/plugin-auth 0.86.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5321 -0
- package/README.md +83 -0
- package/THIRD-PARTY-NOTICES.md +1130 -11
- package/dist/authExtensions.js +9 -0
- package/dist/emailVerification.js +13 -11
- package/dist/guest.d.ts +99 -0
- package/dist/guest.js +3 -0
- package/dist/guestClient.js +237 -0
- package/dist/guestCredential.js +12 -0
- package/dist/guestPasswordUpgrade.js +85 -0
- package/dist/guestPlugin.js +166 -0
- package/dist/guestSchema.js +20 -0
- package/dist/guestSecrets.js +10 -0
- package/dist/guestService.js +224 -0
- package/dist/handlers.js +113 -113
- package/dist/impersonation.js +79 -78
- package/dist/index.d.ts +265 -15
- package/dist/index.js +27 -19
- package/dist/invitations.js +23 -23
- package/dist/native/guestStorage.js +41 -0
- package/dist/native.d.ts +110 -0
- package/dist/native.js +45 -43
- package/dist/nativeRoutes.js +61 -72
- package/dist/overlayPlugin.js +167 -0
- package/dist/plugin.d.ts +119 -10
- package/dist/plugin.js +99 -78
- package/dist/postgresUserStore.js +19 -7
- package/dist/revocation.js +40 -23
- package/dist/schema.d.ts +41 -1
- package/dist/schema.js +99 -98
- package/dist/sessionFamily.js +15 -0
- package/dist/sessionRegistry.js +93 -78
- package/dist/signedClaims.js +24 -0
- package/dist/strategy.d.ts +13 -9
- package/dist/strategy.js +26 -22
- package/dist/userStore.js +145 -138
- package/dist/web/guestStorage.js +47 -0
- package/dist/web.d.ts +94 -0
- package/dist/web.js +4 -2
- package/package.json +8 -3
package/dist/handlers.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { hashPassword as e, verifyPassword as t, verifyPasswordWithRehash as n } from "./password.js";
|
|
2
2
|
import { SESSION_COOKIE_NAME as r, clearSessionCookie as i, issueSession as a, resolveSessionSecret as o, resolveSessionSecrets as s, sessionSecretsOf as c } from "./session.js";
|
|
3
3
|
import { newAuthId as l, subjectFromUser as u } from "./userStore.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { CSRF_COOKIE_NAME as d, issueCsrfToken as f } from "./csrf.js";
|
|
5
|
+
import { decideAdmission as p } from "./admission.js";
|
|
6
|
+
import { generateRecoveryCodes as m, generateTotpSecret as h, otpauthUrl as g, verifyTotpCode as _ } from "./totp.js";
|
|
7
|
+
import { MFA_PENDING_TTL_S as v, hashToken as y, mintToken as b } from "./tokens.js";
|
|
8
|
+
import { runSubjectGuards as x } from "./subjectGuard.js";
|
|
9
9
|
import { EMAIL_VERIFIED_METADATA_KEY as S, emailVerificationActive as C, sendEmailVerification as w, userEmailVerified as T } from "./emailVerification.js";
|
|
10
10
|
import { Effect as E } from "effect";
|
|
11
11
|
import { buildSetCookie as D } from "@voltro/protocol/session";
|
|
12
12
|
import { writeTenantSelection as O } from "@voltro/database";
|
|
13
13
|
import { selectSubjectTenant as k } from "@voltro/protocol";
|
|
14
14
|
//#region src/handlers.ts
|
|
15
|
-
var A = 5, j = 900, M = 900, N = (e) => ({
|
|
15
|
+
var A = 5, j = 900, M = 900, N = (e) => e.email ?? `user:${e.id}`, P = (e) => ({
|
|
16
16
|
maxAttempts: e.lockout?.maxAttempts ?? A,
|
|
17
17
|
windowMs: (e.lockout?.windowSeconds ?? j) * 1e3,
|
|
18
18
|
lockMs: (e.lockout?.lockSeconds ?? M) * 1e3
|
|
19
|
-
}),
|
|
19
|
+
}), F = (e) => e.secrets ?? (e.secret === void 0 ? s() : c(e.secret)), I = (e) => e.secret ?? o(), L = (e, t, n = {}) => ({
|
|
20
20
|
status: e,
|
|
21
21
|
body: JSON.stringify(t),
|
|
22
22
|
contentType: "application/json; charset=utf-8",
|
|
23
23
|
...n
|
|
24
|
-
}),
|
|
24
|
+
}), R = (e, t = {}) => ({
|
|
25
25
|
status: 302,
|
|
26
26
|
body: "",
|
|
27
27
|
contentType: "text/plain",
|
|
28
28
|
location: e,
|
|
29
29
|
...t
|
|
30
|
-
}),
|
|
30
|
+
}), z = 604800, B = (e, t) => e.type === "user" ? {
|
|
31
31
|
...e,
|
|
32
32
|
metadata: {
|
|
33
33
|
...e.metadata ?? {},
|
|
34
34
|
sessionId: t
|
|
35
35
|
}
|
|
36
|
-
} : e,
|
|
37
|
-
r.clearLoginFailures !== !1 && (yield* t.clearLoginFailures(e
|
|
38
|
-
let i = yield* t.listMemberships(e.id), o = r.sessionId ?? l("sess"), s = r.ttlSeconds ??
|
|
36
|
+
} : e, V = (e, t, n, r = {}) => E.gen(function* () {
|
|
37
|
+
r.clearLoginFailures !== !1 && (yield* t.clearLoginFailures(N(e))), n.ensureActor && (yield* n.ensureActor(e));
|
|
38
|
+
let i = yield* t.listMemberships(e.id), o = r.sessionId ?? l("sess"), s = r.ttlSeconds ?? z;
|
|
39
39
|
r.sessionRow !== "existing" && (yield* t.insertSession({
|
|
40
40
|
id: o,
|
|
41
41
|
userId: e.id,
|
|
@@ -46,10 +46,10 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
46
46
|
}).pipe(E.ignore));
|
|
47
47
|
let c = { ...r.metadata };
|
|
48
48
|
C(n.emailVerification) && (c[S] = T(e, n.emailVerification));
|
|
49
|
-
let d =
|
|
49
|
+
let d = B(u(e, {
|
|
50
50
|
memberships: i,
|
|
51
51
|
...Object.keys(c).length > 0 ? { metadata: c } : {}
|
|
52
|
-
}), o), f = a(d,
|
|
52
|
+
}), o), f = a(d, F(n), {
|
|
53
53
|
ttlSeconds: s,
|
|
54
54
|
...n.cookieDomain ? { domain: n.cookieDomain } : {},
|
|
55
55
|
secure: n.cookieSecure ?? !0
|
|
@@ -60,18 +60,18 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
60
60
|
expiresAt: Math.floor(Date.now() / 1e3) + s,
|
|
61
61
|
subject: d
|
|
62
62
|
};
|
|
63
|
-
}),
|
|
63
|
+
}), H = (e, t) => E.gen(function* () {
|
|
64
64
|
let n = t.subjectGuards ?? [];
|
|
65
65
|
if (n.length === 0) return null;
|
|
66
|
-
let r = yield*
|
|
67
|
-
return r.ok ? null :
|
|
66
|
+
let r = yield* x(n, e);
|
|
67
|
+
return r.ok ? null : L(403, {
|
|
68
68
|
error: r.code,
|
|
69
69
|
message: r.message
|
|
70
70
|
});
|
|
71
|
-
}),
|
|
72
|
-
if (!r.email || !r.password) return
|
|
71
|
+
}), U = (r, i, a) => E.gen(function* () {
|
|
72
|
+
if (!r.email || !r.password) return L(400, { error: "email and password required" });
|
|
73
73
|
let o = yield* i.findByEmail(r.email), s = (a.now ?? Date.now)(), c = yield* i.isLockedOut(r.email, s);
|
|
74
|
-
if (c.locked) return
|
|
74
|
+
if (c.locked) return L(429, {
|
|
75
75
|
error: "account_locked",
|
|
76
76
|
retryAfterSeconds: c.retryAfterSeconds
|
|
77
77
|
});
|
|
@@ -79,65 +79,65 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
79
79
|
let n = yield* e("decoy-not-a-real-password").pipe(E.orElseSucceed(() => ""));
|
|
80
80
|
return yield* t(r.password, n), { valid: !1 };
|
|
81
81
|
});
|
|
82
|
-
if (!o || !d.valid) return yield* i.recordLoginFailure(r.email, s,
|
|
83
|
-
let f = yield*
|
|
82
|
+
if (!o || !d.valid) return yield* i.recordLoginFailure(r.email, s, P(a)), L(401, { error: "invalid credentials" });
|
|
83
|
+
let f = yield* H(o, a);
|
|
84
84
|
if (f) return f;
|
|
85
85
|
if (d.rehash && (yield* i.updatePassword(o.id, d.rehash).pipe(E.ignore)), o.mfaEnrolledAt) {
|
|
86
|
-
let e =
|
|
86
|
+
let e = b("mfa-pending", 300);
|
|
87
87
|
return yield* i.insertToken({
|
|
88
88
|
id: l("tok"),
|
|
89
89
|
tokenHash: e.tokenHash,
|
|
90
90
|
userId: o.id,
|
|
91
91
|
purpose: "mfa-pending",
|
|
92
92
|
expiresAt: e.expiresAt
|
|
93
|
-
}).pipe(E.ignore),
|
|
93
|
+
}).pipe(E.ignore), L(200, {
|
|
94
94
|
ok: !0,
|
|
95
95
|
mfaRequired: !0,
|
|
96
96
|
pendingToken: e.token,
|
|
97
97
|
expiresInSeconds: 300
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
let { setCookie: p, subject: m } = yield*
|
|
100
|
+
let { setCookie: p, subject: m } = yield* V(o, i, a, {
|
|
101
101
|
ipAddress: r.ipAddress ?? null,
|
|
102
102
|
userAgent: r.userAgent ?? null
|
|
103
103
|
});
|
|
104
|
-
return r.redirectAfter ?
|
|
104
|
+
return r.redirectAfter ? R(a.successRedirect ?? "/", { setCookie: p }) : L(200, {
|
|
105
105
|
ok: !0,
|
|
106
106
|
subject: m
|
|
107
107
|
}, { setCookie: p });
|
|
108
|
-
}),
|
|
109
|
-
if (!e.pendingToken) return
|
|
110
|
-
if (!e.code && !e.recoveryCode) return
|
|
111
|
-
let r = yield* t.consumeToken(
|
|
112
|
-
if (!r) return
|
|
108
|
+
}), W = (e, t, n) => E.gen(function* () {
|
|
109
|
+
if (!e.pendingToken) return L(400, { error: "pending token required" });
|
|
110
|
+
if (!e.code && !e.recoveryCode) return L(400, { error: "code or recoveryCode required" });
|
|
111
|
+
let r = yield* t.consumeToken(y(e.pendingToken), "mfa-pending");
|
|
112
|
+
if (!r) return L(401, { error: "invalid or expired challenge" });
|
|
113
113
|
let i = yield* t.findById(r.userId);
|
|
114
|
-
if (!i || !i.mfaEnrolledAt || !i.mfaSecret) return
|
|
115
|
-
let a = (n.now ?? Date.now)(), o = yield* t.isLockedOut(i
|
|
116
|
-
if (o.locked) return
|
|
114
|
+
if (!i || !i.mfaEnrolledAt || !i.mfaSecret) return L(401, { error: "mfa not enrolled" });
|
|
115
|
+
let a = (n.now ?? Date.now)(), o = yield* t.isLockedOut(N(i), a);
|
|
116
|
+
if (o.locked) return L(429, {
|
|
117
117
|
error: "account_locked",
|
|
118
118
|
retryAfterSeconds: o.retryAfterSeconds
|
|
119
119
|
});
|
|
120
|
-
let s = yield*
|
|
120
|
+
let s = yield* H(i, n);
|
|
121
121
|
if (s) return s;
|
|
122
|
-
if (!(e.recoveryCode ? yield* t.consumeRecoveryCode(i.id,
|
|
123
|
-
let { setCookie: c, subject: l } = yield*
|
|
122
|
+
if (!(e.recoveryCode ? yield* t.consumeRecoveryCode(i.id, y(e.recoveryCode.trim())) : yield* _(i.mfaSecret, e.code ?? "").pipe(E.map(() => !0), E.catchTag("TotpVerifyError", () => E.succeed(!1))))) return yield* t.recordLoginFailure(N(i), a, P(n)), L(401, { error: "invalid_code" });
|
|
123
|
+
let { setCookie: c, subject: l } = yield* V(i, t, n, {
|
|
124
124
|
ipAddress: e.ipAddress ?? null,
|
|
125
125
|
userAgent: e.userAgent ?? null
|
|
126
126
|
});
|
|
127
|
-
return e.redirectAfter ?
|
|
127
|
+
return e.redirectAfter ? R(n.successRedirect ?? "/", { setCookie: c }) : L(200, {
|
|
128
128
|
ok: !0,
|
|
129
129
|
subject: l
|
|
130
130
|
}, { setCookie: c });
|
|
131
|
-
}),
|
|
132
|
-
if (!t.email || !t.password) return
|
|
133
|
-
if (t.password.length < 8) return
|
|
134
|
-
if (yield* n.findByEmail(t.email)) return
|
|
135
|
-
let i = t.tenantId ?? r.defaultTenantId, a = yield*
|
|
131
|
+
}), G = (t, n, r) => E.gen(function* () {
|
|
132
|
+
if (!t.email || !t.password) return L(400, { error: "email and password required" });
|
|
133
|
+
if (t.password.length < 8) return L(400, { error: "password must be at least 8 characters" });
|
|
134
|
+
if (yield* n.findByEmail(t.email)) return L(409, { error: "email already registered" });
|
|
135
|
+
let i = t.tenantId ?? r.defaultTenantId, a = yield* p(r.admit, {
|
|
136
136
|
email: t.email,
|
|
137
137
|
tenantId: i,
|
|
138
138
|
via: "sign-up"
|
|
139
139
|
});
|
|
140
|
-
if (a) return
|
|
140
|
+
if (a) return L(403, {
|
|
141
141
|
error: "not_admitted",
|
|
142
142
|
reason: a.reason,
|
|
143
143
|
message: a.message
|
|
@@ -153,15 +153,15 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
153
153
|
tenantId: i,
|
|
154
154
|
role: "owner"
|
|
155
155
|
}).pipe(E.ignore), C(r.emailVerification) && (r.emailVerification?.sendOnSignUp ?? !0) && (yield* w(s, n, r).pipe(E.ignore));
|
|
156
|
-
let { setCookie: c, subject: u } = yield*
|
|
157
|
-
return t.redirectAfter ?
|
|
156
|
+
let { setCookie: c, subject: u } = yield* V(s, n, r);
|
|
157
|
+
return t.redirectAfter ? R(r.successRedirect ?? "/", { setCookie: c }) : L(200, {
|
|
158
158
|
ok: !0,
|
|
159
159
|
subject: u
|
|
160
160
|
}, { setCookie: c });
|
|
161
|
-
}).pipe(E.catch((e) => E.succeed(
|
|
161
|
+
}).pipe(E.catch((e) => E.succeed(L(500, {
|
|
162
162
|
error: "signup_failed",
|
|
163
163
|
cause: String(e)
|
|
164
|
-
})))),
|
|
164
|
+
})))), K = (e) => ({
|
|
165
165
|
status: 302,
|
|
166
166
|
body: "",
|
|
167
167
|
location: e.successRedirect ?? "/",
|
|
@@ -169,61 +169,61 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
169
169
|
...e.cookieDomain ? { domain: e.cookieDomain } : {},
|
|
170
170
|
secure: e.cookieSecure ?? !0
|
|
171
171
|
})
|
|
172
|
-
}),
|
|
172
|
+
}), q = (e, t) => E.gen(function* () {
|
|
173
173
|
let n = yield* t.findById(e.userId);
|
|
174
|
-
if (!n) return
|
|
175
|
-
let r =
|
|
176
|
-
return yield* t.setMfaSecret(n.id, r).pipe(E.catch(() => E.succeed(n))),
|
|
174
|
+
if (!n) return L(404, { error: "user_not_found" });
|
|
175
|
+
let r = h();
|
|
176
|
+
return yield* t.setMfaSecret(n.id, r).pipe(E.catch(() => E.succeed(n))), L(200, {
|
|
177
177
|
ok: !0,
|
|
178
178
|
secret: r,
|
|
179
|
-
otpauthUrl:
|
|
179
|
+
otpauthUrl: g({
|
|
180
180
|
issuer: e.issuer,
|
|
181
181
|
accountName: e.accountName,
|
|
182
182
|
secret: r
|
|
183
183
|
})
|
|
184
184
|
});
|
|
185
|
-
}),
|
|
185
|
+
}), J = (e, t) => E.gen(function* () {
|
|
186
186
|
let n = yield* t.findById(e.userId);
|
|
187
|
-
if (!n) return
|
|
188
|
-
if (!n.mfaSecret) return
|
|
189
|
-
if (n.mfaEnrolledAt) return
|
|
190
|
-
if (!(yield*
|
|
187
|
+
if (!n) return L(404, { error: "user_not_found" });
|
|
188
|
+
if (!n.mfaSecret) return L(400, { error: "no_enrollment_in_progress" });
|
|
189
|
+
if (n.mfaEnrolledAt) return L(409, { error: "already_enrolled" });
|
|
190
|
+
if (!(yield* _(n.mfaSecret, e.code).pipe(E.map(() => !0), E.catchTag("TotpVerifyError", () => E.succeed(!1))))) return L(401, { error: "invalid_code" });
|
|
191
191
|
yield* t.markMfaEnrolled(n.id).pipe(E.catch(() => E.succeed(n)));
|
|
192
|
-
let r =
|
|
193
|
-
return yield* t.replaceRecoveryCodes(n.id, r.map((e) =>
|
|
192
|
+
let r = m();
|
|
193
|
+
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => y(e))).pipe(E.ignore), L(200, {
|
|
194
194
|
ok: !0,
|
|
195
195
|
enrolled: !0,
|
|
196
196
|
recoveryCodes: r
|
|
197
197
|
});
|
|
198
|
-
}),
|
|
198
|
+
}), Y = (e, t) => E.gen(function* () {
|
|
199
199
|
let n = yield* t.findById(e.userId);
|
|
200
|
-
if (!n) return
|
|
201
|
-
if (!n.mfaEnrolledAt) return
|
|
202
|
-
let r =
|
|
203
|
-
return yield* t.replaceRecoveryCodes(n.id, r.map((e) =>
|
|
200
|
+
if (!n) return L(404, { error: "user_not_found" });
|
|
201
|
+
if (!n.mfaEnrolledAt) return L(400, { error: "mfa_not_enrolled" });
|
|
202
|
+
let r = m();
|
|
203
|
+
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => y(e))).pipe(E.ignore), L(200, {
|
|
204
204
|
ok: !0,
|
|
205
205
|
recoveryCodes: r
|
|
206
206
|
});
|
|
207
|
-
}),
|
|
207
|
+
}), X = (e, t) => E.gen(function* () {
|
|
208
208
|
let n = yield* t.findById(e.userId);
|
|
209
|
-
return n ? (yield* t.clearMfa(n.id).pipe(E.catch(() => E.succeed(n))), yield* t.replaceRecoveryCodes(n.id, []).pipe(E.ignore),
|
|
209
|
+
return n ? (yield* t.clearMfa(n.id).pipe(E.catch(() => E.succeed(n))), yield* t.replaceRecoveryCodes(n.id, []).pipe(E.ignore), L(200, {
|
|
210
210
|
ok: !0,
|
|
211
211
|
enrolled: !1
|
|
212
|
-
})) :
|
|
213
|
-
}),
|
|
214
|
-
let t =
|
|
212
|
+
})) : L(404, { error: "user_not_found" });
|
|
213
|
+
}), Z = (e) => {
|
|
214
|
+
let t = f(I(e)), n = D(d, t, {
|
|
215
215
|
httpOnly: !1,
|
|
216
216
|
sameSite: "lax",
|
|
217
217
|
secure: e.cookieSecure ?? !0,
|
|
218
218
|
...e.cookieDomain ? { domain: e.cookieDomain } : {},
|
|
219
219
|
path: "/"
|
|
220
220
|
});
|
|
221
|
-
return
|
|
222
|
-
},
|
|
223
|
-
if (!e.email) return
|
|
221
|
+
return L(200, { csrfToken: t }, { setCookie: n });
|
|
222
|
+
}, Q = (e, t, n) => `${e}${t}${t.includes("?") ? "&" : "?"}token=${encodeURIComponent(n)}`, $ = (e, t, n) => E.gen(function* () {
|
|
223
|
+
if (!e.email) return L(400, { error: "email required" });
|
|
224
224
|
let r = yield* t.findByEmail(e.email);
|
|
225
225
|
if (r) {
|
|
226
|
-
let i =
|
|
226
|
+
let i = b("magic-link");
|
|
227
227
|
yield* t.insertToken({
|
|
228
228
|
id: l("tok"),
|
|
229
229
|
tokenHash: i.tokenHash,
|
|
@@ -231,9 +231,9 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
231
231
|
purpose: "magic-link",
|
|
232
232
|
expiresAt: i.expiresAt
|
|
233
233
|
}).pipe(E.ignore);
|
|
234
|
-
let a =
|
|
234
|
+
let a = Q(n.appBaseUrl ?? "", e.callbackPath ?? "/auth/magic-link/callback", i.token);
|
|
235
235
|
n.sendEmail && (yield* E.tryPromise(() => n.sendEmail({
|
|
236
|
-
to: r.email,
|
|
236
|
+
to: r.email ?? e.email,
|
|
237
237
|
kind: "magic-link",
|
|
238
238
|
actionUrl: a,
|
|
239
239
|
subject: "Your sign-in link",
|
|
@@ -241,25 +241,25 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
241
241
|
html: `<p><a href="${a}">Sign in</a> — this link expires shortly.</p>`
|
|
242
242
|
})).pipe(E.ignore));
|
|
243
243
|
}
|
|
244
|
-
return
|
|
245
|
-
}),
|
|
246
|
-
if (!e.token) return
|
|
247
|
-
let r = yield* t.consumeToken(
|
|
248
|
-
if (!r) return
|
|
244
|
+
return L(202, { ok: !0 });
|
|
245
|
+
}), ee = (e, t, n) => E.gen(function* () {
|
|
246
|
+
if (!e.token) return L(400, { error: "token required" });
|
|
247
|
+
let r = yield* t.consumeToken(y(e.token), "magic-link");
|
|
248
|
+
if (!r) return L(401, { error: "invalid or expired token" });
|
|
249
249
|
let i = yield* t.findById(r.userId);
|
|
250
|
-
if (!i) return
|
|
251
|
-
let a = yield* t.markEmailVerified(i.id).pipe(E.orElseSucceed(() => i)), o = yield*
|
|
250
|
+
if (!i) return L(401, { error: "invalid or expired token" });
|
|
251
|
+
let a = yield* t.markEmailVerified(i.id).pipe(E.orElseSucceed(() => i)), o = yield* H(a, n);
|
|
252
252
|
if (o) return o;
|
|
253
|
-
let { setCookie: s, subject: c } = yield*
|
|
254
|
-
return e.redirectAfter ?
|
|
253
|
+
let { setCookie: s, subject: c } = yield* V(a, t, n);
|
|
254
|
+
return e.redirectAfter ? R(n.successRedirect ?? "/", { setCookie: s }) : L(200, {
|
|
255
255
|
ok: !0,
|
|
256
256
|
subject: c
|
|
257
257
|
}, { setCookie: s });
|
|
258
|
-
}),
|
|
259
|
-
if (!e.email) return
|
|
258
|
+
}), te = (e, t, n) => E.gen(function* () {
|
|
259
|
+
if (!e.email) return L(400, { error: "email required" });
|
|
260
260
|
let r = yield* t.findByEmail(e.email);
|
|
261
261
|
if (r) {
|
|
262
|
-
let i =
|
|
262
|
+
let i = b("password-reset");
|
|
263
263
|
yield* t.insertToken({
|
|
264
264
|
id: l("tok"),
|
|
265
265
|
tokenHash: i.tokenHash,
|
|
@@ -267,9 +267,9 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
267
267
|
purpose: "password-reset",
|
|
268
268
|
expiresAt: i.expiresAt
|
|
269
269
|
}).pipe(E.ignore);
|
|
270
|
-
let a =
|
|
270
|
+
let a = Q(n.appBaseUrl ?? "", e.callbackPath ?? "/auth/password-reset/callback", i.token);
|
|
271
271
|
n.sendEmail && (yield* E.tryPromise(() => n.sendEmail({
|
|
272
|
-
to: r.email,
|
|
272
|
+
to: r.email ?? e.email,
|
|
273
273
|
kind: "password-reset",
|
|
274
274
|
actionUrl: a,
|
|
275
275
|
subject: "Reset your password",
|
|
@@ -277,16 +277,16 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
277
277
|
html: `<p><a href="${a}">Reset your password</a> — this link expires shortly.</p>`
|
|
278
278
|
})).pipe(E.ignore));
|
|
279
279
|
}
|
|
280
|
-
return
|
|
281
|
-
}),
|
|
282
|
-
if (!t.token || !t.newPassword) return
|
|
283
|
-
if (t.newPassword.length < 8) return
|
|
284
|
-
let r = yield* n.consumeToken(
|
|
285
|
-
if (!r) return
|
|
280
|
+
return L(202, { ok: !0 });
|
|
281
|
+
}), ne = (t, n) => E.gen(function* () {
|
|
282
|
+
if (!t.token || !t.newPassword) return L(400, { error: "token and newPassword required" });
|
|
283
|
+
if (t.newPassword.length < 8) return L(400, { error: "password must be at least 8 characters" });
|
|
284
|
+
let r = yield* n.consumeToken(y(t.token), "password-reset");
|
|
285
|
+
if (!r) return L(401, { error: "invalid or expired token" });
|
|
286
286
|
let i = yield* e(t.newPassword).pipe(E.orElseSucceed(() => ""));
|
|
287
|
-
return i ? (yield* n.updatePassword(r.userId, i).pipe(E.ignore), yield* n.markEmailVerified(r.userId).pipe(E.ignore), yield* n.revokeAllSessions(r.userId).pipe(E.ignore),
|
|
288
|
-
}),
|
|
289
|
-
return
|
|
287
|
+
return i ? (yield* n.updatePassword(r.userId, i).pipe(E.ignore), yield* n.markEmailVerified(r.userId).pipe(E.ignore), yield* n.revokeAllSessions(r.userId).pipe(E.ignore), L(200, { ok: !0 })) : L(500, { error: "hash_failed" });
|
|
288
|
+
}), re = (e, t) => E.gen(function* () {
|
|
289
|
+
return L(200, { sessions: (yield* t.listSessions(e.userId)).map((e) => ({
|
|
290
290
|
id: e.id,
|
|
291
291
|
tenantId: e.tenantId,
|
|
292
292
|
ipAddress: e.ipAddress ?? null,
|
|
@@ -295,43 +295,43 @@ var A = 5, j = 900, M = 900, N = (e) => ({
|
|
|
295
295
|
lastSeenAt: e.lastSeenAt.toISOString(),
|
|
296
296
|
expiresAt: e.expiresAt.toISOString()
|
|
297
297
|
})) });
|
|
298
|
-
}),
|
|
299
|
-
return (yield* t.revokeSession(e.userId, e.sessionId)) ?
|
|
298
|
+
}), ie = (e, t) => E.gen(function* () {
|
|
299
|
+
return (yield* t.revokeSession(e.userId, e.sessionId)) ? L(200, {
|
|
300
300
|
ok: !0,
|
|
301
301
|
revoked: 1
|
|
302
|
-
}) :
|
|
303
|
-
}),
|
|
304
|
-
return
|
|
302
|
+
}) : L(404, { error: "session_not_found" });
|
|
303
|
+
}), ae = (e, t) => E.gen(function* () {
|
|
304
|
+
return L(200, {
|
|
305
305
|
ok: !0,
|
|
306
306
|
revoked: yield* t.revokeAllOtherSessions(e.userId, e.keepSessionId)
|
|
307
307
|
});
|
|
308
|
-
}),
|
|
308
|
+
}), oe = (e, t, n, i, o) => E.gen(function* () {
|
|
309
309
|
let s = yield* t.findById(e.userId);
|
|
310
|
-
if (!s) return
|
|
310
|
+
if (!s) return L(404, { error: "user_not_found" });
|
|
311
311
|
let c = yield* t.listMemberships(s.id), l = c.find((t) => t.tenantId === e.targetTenantId)?.role ?? null;
|
|
312
|
-
if (l === null) return
|
|
312
|
+
if (l === null) return L(403, { error: "not a member of the target tenant" });
|
|
313
313
|
let d = e.metadata === void 0 ? void 0 : Object.fromEntries(Object.entries(e.metadata).filter(([e]) => e !== "memberships")), f = k(u(s, { ...d === void 0 ? {} : { metadata: d } }), e.targetTenantId, c);
|
|
314
314
|
o !== void 0 && f.type === "user" && (yield* E.promise(() => O(o, {
|
|
315
315
|
type: f.type,
|
|
316
316
|
id: f.id
|
|
317
317
|
}, e.targetTenantId)));
|
|
318
|
-
let p = e.sessionId ?
|
|
319
|
-
ttlSeconds:
|
|
318
|
+
let p = e.sessionId ? B(f, e.sessionId) : f, m = a(p, F(n), {
|
|
319
|
+
ttlSeconds: z,
|
|
320
320
|
...n.cookieDomain ? { domain: n.cookieDomain } : {},
|
|
321
321
|
secure: n.cookieSecure ?? !0
|
|
322
322
|
});
|
|
323
|
-
return e.clientId !== void 0 && i && i(e.clientId, { cookies: { [r]: m.value } }),
|
|
323
|
+
return e.clientId !== void 0 && i && i(e.clientId, { cookies: { [r]: m.value } }), L(200, {
|
|
324
324
|
ok: !0,
|
|
325
325
|
tenantId: e.targetTenantId,
|
|
326
326
|
role: l,
|
|
327
327
|
subject: p
|
|
328
328
|
}, { setCookie: m.setCookie });
|
|
329
|
-
}),
|
|
330
|
-
return
|
|
329
|
+
}), se = (e, t) => E.gen(function* () {
|
|
330
|
+
return L(200, { memberships: (yield* t.listMemberships(e.userId)).map((e) => ({
|
|
331
331
|
tenantId: e.tenantId,
|
|
332
332
|
role: e.role,
|
|
333
333
|
joinedAt: e.joinedAt.toISOString()
|
|
334
334
|
})) });
|
|
335
335
|
});
|
|
336
336
|
//#endregion
|
|
337
|
-
export {
|
|
337
|
+
export { v as MFA_PENDING_TTL_S, F as configSessionSecrets, I as configSigningKey, H as guardSubject, Z as handleCsrf, se as handleListMemberships, re as handleListSessions, ee as handleMagicLinkConsume, $ as handleMagicLinkRequest, q as handleMfaEnrollStart, J as handleMfaEnrollVerify, Y as handleMfaRegenerateRecoveryCodes, X as handleMfaUnenroll, W as handleMfaVerify, ne as handlePasswordResetConfirm, te as handlePasswordResetRequest, ae as handleRevokeAllOtherSessions, ie as handleRevokeSession, U as handleSignIn, K as handleSignOut, G as handleSignUp, oe as handleSwitchTenant, V as issueUserSession };
|