@fonderie/auth 2.0.0 → 3.0.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/brain/signatures.md +1 -0
- package/dist/index.cjs +38 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +38 -27
- package/dist/index.js.map +1 -1
- package/dist/middlewares/index.d.cts +1 -1
- package/dist/middlewares/index.d.ts +1 -1
- package/dist/{session-DbtCnbiG.d.cts → session-BoJjRB7t.d.cts} +6 -0
- package/dist/{session-DbtCnbiG.d.ts → session-BoJjRB7t.d.ts} +6 -0
- package/package.json +4 -4
package/brain/signatures.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -753,6 +753,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
753
753
|
await users.confirmMfaSecret(ctx.user.id);
|
|
754
754
|
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
755
755
|
type: MESSAGE_KEYS.mfaEnabled,
|
|
756
|
+
locale: ctx.user.locale,
|
|
756
757
|
data: {},
|
|
757
758
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
758
759
|
}).catch(() => {
|
|
@@ -844,6 +845,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
844
845
|
await backupCodes.replace(ctx.user.id, codeHashes);
|
|
845
846
|
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
846
847
|
type: MESSAGE_KEYS.mfaBackupCodesRegenerated,
|
|
848
|
+
locale: ctx.user.locale,
|
|
847
849
|
data: {},
|
|
848
850
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
849
851
|
}).catch(() => {
|
|
@@ -870,6 +872,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
870
872
|
await Promise.all([users.disableMfa(ctx.user.id), backupCodes.deleteByUser(ctx.user.id)]);
|
|
871
873
|
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
872
874
|
type: MESSAGE_KEYS.mfaDisabled,
|
|
875
|
+
locale: user.locale,
|
|
873
876
|
data: {},
|
|
874
877
|
recipient: { email: user.email, phone: null, deviceToken: null }
|
|
875
878
|
}).catch(() => {
|
|
@@ -1117,6 +1120,7 @@ function authController(store, config, bus) {
|
|
|
1117
1120
|
import_events2.NOTIFICATION_EVENT,
|
|
1118
1121
|
{
|
|
1119
1122
|
type: MESSAGE_KEYS.emailRegistration,
|
|
1123
|
+
locale: user.locale,
|
|
1120
1124
|
data: { pin, firstName: firstName ?? "" },
|
|
1121
1125
|
recipient: { email: normalizedEmail, phone: null, deviceToken: null }
|
|
1122
1126
|
},
|
|
@@ -1180,6 +1184,7 @@ function authController(store, config, bus) {
|
|
|
1180
1184
|
import_events2.NOTIFICATION_EVENT,
|
|
1181
1185
|
{
|
|
1182
1186
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1187
|
+
locale: user.locale,
|
|
1183
1188
|
data: { otp },
|
|
1184
1189
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1185
1190
|
},
|
|
@@ -1292,6 +1297,7 @@ function authController(store, config, bus) {
|
|
|
1292
1297
|
await phoneVerif.upsert(user.id, normalizePhone(phone2), otp, expiresAt);
|
|
1293
1298
|
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1294
1299
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1300
|
+
locale: user.locale,
|
|
1295
1301
|
data: { otp },
|
|
1296
1302
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1297
1303
|
}).catch(() => {
|
|
@@ -1406,6 +1412,7 @@ function authController(store, config, bus) {
|
|
|
1406
1412
|
await passwordReset.create(user.id, pin, expiresAt);
|
|
1407
1413
|
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1408
1414
|
type: MESSAGE_KEYS.passwordReset,
|
|
1415
|
+
locale: user.locale,
|
|
1409
1416
|
recipient: { email: email2, phone: null, deviceToken: null },
|
|
1410
1417
|
data: { pin }
|
|
1411
1418
|
}).catch(() => {
|
|
@@ -1572,6 +1579,7 @@ function authController(store, config, bus) {
|
|
|
1572
1579
|
await phoneVerif.upsert(ctx.user.id, phone2, otp, expiresAt2);
|
|
1573
1580
|
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1574
1581
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1582
|
+
locale: ctx.user.locale,
|
|
1575
1583
|
data: { otp },
|
|
1576
1584
|
recipient: { email: null, phone: phone2, deviceToken: null }
|
|
1577
1585
|
}).catch(() => {
|
|
@@ -1611,6 +1619,7 @@ function authController(store, config, bus) {
|
|
|
1611
1619
|
await emailVerif.replace(ctx.user.id, pin, expiresAt);
|
|
1612
1620
|
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1613
1621
|
type: MESSAGE_KEYS.emailVerification,
|
|
1622
|
+
locale: ctx.user.locale,
|
|
1614
1623
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null },
|
|
1615
1624
|
data: { pin }
|
|
1616
1625
|
}).catch(() => {
|
|
@@ -1722,6 +1731,7 @@ function userController(store, config, bus) {
|
|
|
1722
1731
|
await users.updateEmail(ctx.user.id, normalised);
|
|
1723
1732
|
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
1724
1733
|
type: MESSAGE_KEYS.emailVerification,
|
|
1734
|
+
locale: ctx.user.locale,
|
|
1725
1735
|
data: { pin },
|
|
1726
1736
|
recipient: { email: normalised, phone: null, deviceToken: null }
|
|
1727
1737
|
}).catch(() => {
|
|
@@ -1729,6 +1739,7 @@ function userController(store, config, bus) {
|
|
|
1729
1739
|
if (oldEmail) {
|
|
1730
1740
|
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
1731
1741
|
type: MESSAGE_KEYS.emailChanged,
|
|
1742
|
+
locale: ctx.user.locale,
|
|
1732
1743
|
data: { newEmail: normalised },
|
|
1733
1744
|
recipient: { email: oldEmail, phone: null, deviceToken: null }
|
|
1734
1745
|
}).catch(() => {
|
|
@@ -1764,6 +1775,7 @@ function userController(store, config, bus) {
|
|
|
1764
1775
|
await users.updatePhone(ctx.user.id, normalised);
|
|
1765
1776
|
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
1766
1777
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1778
|
+
locale: ctx.user.locale,
|
|
1767
1779
|
data: { otp },
|
|
1768
1780
|
recipient: { email: null, phone: normalised, deviceToken: null }
|
|
1769
1781
|
}).catch(() => {
|
|
@@ -1771,6 +1783,7 @@ function userController(store, config, bus) {
|
|
|
1771
1783
|
if (ctx.user.email) {
|
|
1772
1784
|
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
1773
1785
|
type: MESSAGE_KEYS.phoneChanged,
|
|
1786
|
+
locale: ctx.user.locale,
|
|
1774
1787
|
data: {},
|
|
1775
1788
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
1776
1789
|
}).catch(() => {
|
|
@@ -1939,44 +1952,42 @@ function buildAuthRoutes(store, config, bus) {
|
|
|
1939
1952
|
const passthrough = (_ctx, next) => next();
|
|
1940
1953
|
const ipLimit = (route) => buildAuthIpLimiter(route, store, config.rateLimit) ?? passthrough;
|
|
1941
1954
|
const acctLimit = (route) => buildAuthAccountLimiter(route, store, config.rateLimit) ?? passthrough;
|
|
1955
|
+
const R = (id, method, path, ...handlers) => {
|
|
1956
|
+
const o = config.routes?.[id];
|
|
1957
|
+
if (!o) return [method, path, ...handlers];
|
|
1958
|
+
if (typeof o === "string") return [method, o, ...handlers];
|
|
1959
|
+
return [o.method ?? method, o.path ?? path, ...handlers];
|
|
1960
|
+
};
|
|
1942
1961
|
const routes = [
|
|
1943
1962
|
// Registration & Login (Public)
|
|
1944
|
-
|
|
1945
|
-
|
|
1963
|
+
R("register", "POST", "/auth/register", ipLimit("register"), (0, import_middlewares.validate)(registerSchema), auth.register),
|
|
1964
|
+
R("login", "POST", "/auth/login", ipLimit("login"), (0, import_middlewares.validate)(loginSchema), acctLimit("login"), auth.login),
|
|
1946
1965
|
// Token Management (Public)
|
|
1947
|
-
|
|
1966
|
+
R("refresh", "POST", "/auth/refresh", (0, import_middlewares.validate)(refreshSchema), auth.refresh),
|
|
1948
1967
|
// Email — Password Recovery (Public)
|
|
1949
|
-
|
|
1950
|
-
|
|
1968
|
+
R("forgotPassword", "POST", "/auth/email/forgot", ipLimit("forgot"), (0, import_middlewares.validate)(forgotPasswordSchema), acctLimit("forgot"), auth.forgotPassword),
|
|
1969
|
+
R("resetPassword", "POST", "/auth/email/reset", (0, import_middlewares.validate)(resetPasswordSchema), auth.resetPassword),
|
|
1951
1970
|
// Verification (Protected — email or phone, determined by loginMethod)
|
|
1952
|
-
|
|
1953
|
-
|
|
1971
|
+
R("verifyEmail", "POST", "/auth/verify", import_middlewares2.requireAuth, (0, import_middlewares.validate)(verifySchema), auth.verify),
|
|
1972
|
+
R("sendVerification", "GET", "/auth/send-verification", import_middlewares2.requireAuth, auth.sendVerification),
|
|
1954
1973
|
// Account Management (Protected)
|
|
1955
|
-
|
|
1974
|
+
R("logout", "POST", "/auth/logout", import_middlewares2.requireAuth, (0, import_middlewares.validate)(refreshSchema), auth.logout),
|
|
1956
1975
|
// User Profile (Protected; writes also gate on requireVerification)
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1976
|
+
R("me", "GET", "/users", import_middlewares2.requireAuth, user.me),
|
|
1977
|
+
R("updateProfile", "PUT", "/users/profile", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updateProfileSchema), user.updateProfile),
|
|
1978
|
+
R("updatePreferences", "PUT", "/users/preferences", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updatePreferencesSchema), user.updatePreferences),
|
|
1979
|
+
R("updateEmail", "PUT", "/users/email", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updateEmailSchema), user.updateEmail),
|
|
1980
|
+
R("updatePhone", "PUT", "/users/phone", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updatePhoneSchema), user.updatePhone),
|
|
1981
|
+
R("changePassword", "PUT", "/users/password", import_middlewares2.requireAuth, (0, import_middlewares.validate)(changePasswordSchema), user.changePassword),
|
|
1982
|
+
R("deleteMe", "DELETE", "/users", import_middlewares2.requireAuth, verifyGate, user.deleteMe),
|
|
1964
1983
|
// MFA (email sessions only — requireVerified is always enforced here
|
|
1965
1984
|
// because MFA is a security feature and email verification is meaningful)
|
|
1966
|
-
|
|
1985
|
+
R("mfaSetup", "POST", "/auth/mfa/setup", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, mfa.setup),
|
|
1967
1986
|
// /auth/mfa/verify accepts both mfaPending tokens (TOTP/backup-code login)
|
|
1968
1987
|
// and full tokens (setup confirmation), so requireAnyAuth is used here.
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
"POST",
|
|
1973
|
-
"/auth/mfa/backup-codes",
|
|
1974
|
-
import_middlewares2.requireAuth,
|
|
1975
|
-
requireEmailLogin,
|
|
1976
|
-
import_middlewares2.requireVerified,
|
|
1977
|
-
(0, import_middlewares.validate)(mfaTokenSchema),
|
|
1978
|
-
mfa.regenerateBackupCodes
|
|
1979
|
-
]
|
|
1988
|
+
R("mfaVerify", "POST", "/auth/mfa/verify", ipLimit("mfaVerify"), import_middlewares2.requireAnyAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.verify),
|
|
1989
|
+
R("mfaDisable", "POST", "/auth/mfa/disable", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.disable),
|
|
1990
|
+
R("mfaBackupCodes", "POST", "/auth/mfa/backup-codes", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.regenerateBackupCodes)
|
|
1980
1991
|
];
|
|
1981
1992
|
if (config.providers.includes("google")) {
|
|
1982
1993
|
routes.push(
|