@fonderie/auth 7.3.3 → 7.3.4
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.cjs +32 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -51
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1010,13 +1010,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1010
1010
|
return (0, import_core4.setApiResponse)(import_core4.HTTP.UNAUTHORIZED, "INVALID_CODE", "Invalid MFA token");
|
|
1011
1011
|
}
|
|
1012
1012
|
await users.confirmMfaSecret(ctx.user.id);
|
|
1013
|
-
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1013
|
+
await (0, import_core4.background)(bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1014
1014
|
type: MESSAGE_KEYS.mfaEnabled,
|
|
1015
1015
|
locale: ctx.user.locale,
|
|
1016
1016
|
data: {},
|
|
1017
1017
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
1018
|
-
})
|
|
1019
|
-
});
|
|
1018
|
+
}));
|
|
1020
1019
|
return (0, import_core4.setApiResponse)(import_core4.HTTP.OK, "MFA_VERIFIED", "MFA verified successfully.", {
|
|
1021
1020
|
mfaEnabled: true
|
|
1022
1021
|
});
|
|
@@ -1116,13 +1115,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1116
1115
|
const plainCodes = generateBackupCodes();
|
|
1117
1116
|
const codeHashes = await Promise.all(plainCodes.map((c) => hashPassword(c)));
|
|
1118
1117
|
await backupCodes.replace(ctx.user.id, codeHashes);
|
|
1119
|
-
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1118
|
+
await (0, import_core4.background)(bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1120
1119
|
type: MESSAGE_KEYS.mfaBackupCodesRegenerated,
|
|
1121
1120
|
locale: ctx.user.locale,
|
|
1122
1121
|
data: {},
|
|
1123
1122
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
1124
|
-
})
|
|
1125
|
-
});
|
|
1123
|
+
}));
|
|
1126
1124
|
return (0, import_core4.setApiResponse)(import_core4.HTTP.OK, "BACKUP_CODES_REGENERATED", "Backup codes regenerated.", {
|
|
1127
1125
|
backupCodes: plainCodes
|
|
1128
1126
|
});
|
|
@@ -1144,13 +1142,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1144
1142
|
return (0, import_core4.setApiResponse)(import_core4.HTTP.UNAUTHORIZED, "INVALID_CODE", "Invalid TOTP code");
|
|
1145
1143
|
}
|
|
1146
1144
|
await Promise.all([users.disableMfa(ctx.user.id), backupCodes.deleteByUser(ctx.user.id)]);
|
|
1147
|
-
bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1145
|
+
await (0, import_core4.background)(bus?.emit(import_events.NOTIFICATION_EVENT, {
|
|
1148
1146
|
type: MESSAGE_KEYS.mfaDisabled,
|
|
1149
1147
|
locale: user.locale,
|
|
1150
1148
|
data: {},
|
|
1151
1149
|
recipient: { email: user.email, phone: null, deviceToken: null }
|
|
1152
|
-
})
|
|
1153
|
-
});
|
|
1150
|
+
}));
|
|
1154
1151
|
return (0, import_core4.setApiResponse)(import_core4.HTTP.OK, "MFA_DISABLED", "MFA disabled successfully.");
|
|
1155
1152
|
}
|
|
1156
1153
|
};
|
|
@@ -1406,7 +1403,7 @@ function authController(store, config, bus) {
|
|
|
1406
1403
|
}
|
|
1407
1404
|
const reqId = ctx.meta["requestId"];
|
|
1408
1405
|
const reqOpts = reqId !== void 0 ? { requestId: reqId } : void 0;
|
|
1409
|
-
bus?.emit(
|
|
1406
|
+
await (0, import_core5.background)(bus?.emit(
|
|
1410
1407
|
import_events2.NOTIFICATION_EVENT,
|
|
1411
1408
|
{
|
|
1412
1409
|
type: MESSAGE_KEYS.emailRegistration,
|
|
@@ -1415,9 +1412,8 @@ function authController(store, config, bus) {
|
|
|
1415
1412
|
recipient: { email: normalizedEmail, phone: null, deviceToken: null }
|
|
1416
1413
|
},
|
|
1417
1414
|
reqOpts
|
|
1418
|
-
)
|
|
1419
|
-
|
|
1420
|
-
bus?.emit(
|
|
1415
|
+
));
|
|
1416
|
+
await (0, import_core5.background)(bus?.emit(
|
|
1421
1417
|
EVENT_KEYS.userRegistered,
|
|
1422
1418
|
{
|
|
1423
1419
|
userId: user.id,
|
|
@@ -1427,8 +1423,7 @@ function authController(store, config, bus) {
|
|
|
1427
1423
|
loginMethod: "email"
|
|
1428
1424
|
},
|
|
1429
1425
|
reqOpts
|
|
1430
|
-
)
|
|
1431
|
-
});
|
|
1426
|
+
));
|
|
1432
1427
|
const { accessToken, refreshToken, sid } = issueTokenPair(user.id, config, {
|
|
1433
1428
|
loginMethod: "email"
|
|
1434
1429
|
});
|
|
@@ -1470,7 +1465,7 @@ function authController(store, config, bus) {
|
|
|
1470
1465
|
}
|
|
1471
1466
|
const reqId2 = ctx.meta["requestId"];
|
|
1472
1467
|
const reqOpts2 = reqId2 !== void 0 ? { requestId: reqId2 } : void 0;
|
|
1473
|
-
bus?.emit(
|
|
1468
|
+
await (0, import_core5.background)(bus?.emit(
|
|
1474
1469
|
import_events2.NOTIFICATION_EVENT,
|
|
1475
1470
|
{
|
|
1476
1471
|
type: MESSAGE_KEYS.phoneOtp,
|
|
@@ -1479,9 +1474,8 @@ function authController(store, config, bus) {
|
|
|
1479
1474
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1480
1475
|
},
|
|
1481
1476
|
reqOpts2
|
|
1482
|
-
)
|
|
1483
|
-
|
|
1484
|
-
bus?.emit(
|
|
1477
|
+
));
|
|
1478
|
+
await (0, import_core5.background)(bus?.emit(
|
|
1485
1479
|
EVENT_KEYS.userRegistered,
|
|
1486
1480
|
{
|
|
1487
1481
|
userId: user.id,
|
|
@@ -1491,8 +1485,7 @@ function authController(store, config, bus) {
|
|
|
1491
1485
|
loginMethod: "phone"
|
|
1492
1486
|
},
|
|
1493
1487
|
reqOpts2
|
|
1494
|
-
)
|
|
1495
|
-
});
|
|
1488
|
+
));
|
|
1496
1489
|
const otpToken = issueMfaPendingToken(user.id, config, "phone");
|
|
1497
1490
|
return Response.json(
|
|
1498
1491
|
{
|
|
@@ -1610,13 +1603,12 @@ function authController(store, config, bus) {
|
|
|
1610
1603
|
const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
|
|
1611
1604
|
const expiresAt = new Date(Date.now() + OTP_TTL_MS);
|
|
1612
1605
|
await phoneVerif.upsert(user.id, normalizePhone(phone2), otp, expiresAt);
|
|
1613
|
-
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1606
|
+
await (0, import_core5.background)(bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1614
1607
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1615
1608
|
locale: user.locale,
|
|
1616
1609
|
data: { otp },
|
|
1617
1610
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1618
|
-
})
|
|
1619
|
-
});
|
|
1611
|
+
}));
|
|
1620
1612
|
const otpToken = issueMfaPendingToken(user.id, config, "phone");
|
|
1621
1613
|
return Response.json(
|
|
1622
1614
|
{
|
|
@@ -1723,13 +1715,12 @@ function authController(store, config, bus) {
|
|
|
1723
1715
|
await passwordReset.create(user.id, pin, token, expiresAt);
|
|
1724
1716
|
const base = resolved.passwordResetUrl;
|
|
1725
1717
|
const resetUrl = base ? `${base}${base.includes("?") ? "&" : "?"}token=${token}` : "";
|
|
1726
|
-
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1718
|
+
await (0, import_core5.background)(bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1727
1719
|
type: MESSAGE_KEYS.passwordReset,
|
|
1728
1720
|
locale: user.locale,
|
|
1729
1721
|
recipient: { email: email2, phone: null, deviceToken: null },
|
|
1730
1722
|
data: { pin, token, resetUrl }
|
|
1731
|
-
})
|
|
1732
|
-
});
|
|
1723
|
+
}));
|
|
1733
1724
|
return (0, import_core5.setApiResponse)(
|
|
1734
1725
|
import_core5.HTTP.OK,
|
|
1735
1726
|
"PASSWORD_RESET_EMAIL_SENT",
|
|
@@ -1904,13 +1895,12 @@ function authController(store, config, bus) {
|
|
|
1904
1895
|
const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
|
|
1905
1896
|
const expiresAt2 = new Date(Date.now() + OTP_TTL_MS);
|
|
1906
1897
|
await phoneVerif.upsert(ctx.user.id, phone2, otp, expiresAt2);
|
|
1907
|
-
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1898
|
+
await (0, import_core5.background)(bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1908
1899
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1909
1900
|
locale: ctx.user.locale,
|
|
1910
1901
|
data: { otp },
|
|
1911
1902
|
recipient: { email: null, phone: phone2, deviceToken: null }
|
|
1912
|
-
})
|
|
1913
|
-
});
|
|
1903
|
+
}));
|
|
1914
1904
|
return (0, import_core5.setApiResponse)(
|
|
1915
1905
|
import_core5.HTTP.OK,
|
|
1916
1906
|
"VERIFICATION_SENT",
|
|
@@ -1944,13 +1934,12 @@ function authController(store, config, bus) {
|
|
|
1944
1934
|
const pin = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
|
|
1945
1935
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
|
|
1946
1936
|
await emailVerif.replace(ctx.user.id, pin, expiresAt);
|
|
1947
|
-
bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1937
|
+
await (0, import_core5.background)(bus?.emit(import_events2.NOTIFICATION_EVENT, {
|
|
1948
1938
|
type: MESSAGE_KEYS.emailVerification,
|
|
1949
1939
|
locale: ctx.user.locale,
|
|
1950
1940
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null },
|
|
1951
1941
|
data: { pin }
|
|
1952
|
-
})
|
|
1953
|
-
});
|
|
1942
|
+
}));
|
|
1954
1943
|
return (0, import_core5.setApiResponse)(import_core5.HTTP.OK, "VERIFICATION_SENT", "Verification email sent.", {
|
|
1955
1944
|
email: ctx.user.email
|
|
1956
1945
|
});
|
|
@@ -2153,21 +2142,19 @@ function userController(store, config, bus) {
|
|
|
2153
2142
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
|
|
2154
2143
|
await emailVerif.replace(ctx.user.id, pin, expiresAt);
|
|
2155
2144
|
await users.updateEmail(ctx.user.id, normalised);
|
|
2156
|
-
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2145
|
+
await (0, import_core7.background)(bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2157
2146
|
type: MESSAGE_KEYS.emailVerification,
|
|
2158
2147
|
locale: ctx.user.locale,
|
|
2159
2148
|
data: { pin },
|
|
2160
2149
|
recipient: { email: normalised, phone: null, deviceToken: null }
|
|
2161
|
-
})
|
|
2162
|
-
});
|
|
2150
|
+
}));
|
|
2163
2151
|
if (oldEmail) {
|
|
2164
|
-
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2152
|
+
await (0, import_core7.background)(bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2165
2153
|
type: MESSAGE_KEYS.emailChanged,
|
|
2166
2154
|
locale: ctx.user.locale,
|
|
2167
2155
|
data: { newEmail: normalised },
|
|
2168
2156
|
recipient: { email: oldEmail, phone: null, deviceToken: null }
|
|
2169
|
-
})
|
|
2170
|
-
});
|
|
2157
|
+
}));
|
|
2171
2158
|
}
|
|
2172
2159
|
return (0, import_core7.setApiResponse)(
|
|
2173
2160
|
import_core7.HTTP.OK,
|
|
@@ -2197,21 +2184,19 @@ function userController(store, config, bus) {
|
|
|
2197
2184
|
const expiresAt = new Date(Date.now() + 10 * 60 * 1e3);
|
|
2198
2185
|
await phoneVerif.upsert(ctx.user.id, normalised, otp, expiresAt);
|
|
2199
2186
|
await users.updatePhone(ctx.user.id, normalised);
|
|
2200
|
-
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2187
|
+
await (0, import_core7.background)(bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2201
2188
|
type: MESSAGE_KEYS.phoneOtp,
|
|
2202
2189
|
locale: ctx.user.locale,
|
|
2203
2190
|
data: { otp },
|
|
2204
2191
|
recipient: { email: null, phone: normalised, deviceToken: null }
|
|
2205
|
-
})
|
|
2206
|
-
});
|
|
2192
|
+
}));
|
|
2207
2193
|
if (ctx.user.email) {
|
|
2208
|
-
bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2194
|
+
await (0, import_core7.background)(bus?.emit(import_events3.NOTIFICATION_EVENT, {
|
|
2209
2195
|
type: MESSAGE_KEYS.phoneChanged,
|
|
2210
2196
|
locale: ctx.user.locale,
|
|
2211
2197
|
data: {},
|
|
2212
2198
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
2213
|
-
})
|
|
2214
|
-
});
|
|
2199
|
+
}));
|
|
2215
2200
|
}
|
|
2216
2201
|
return (0, import_core7.setApiResponse)(
|
|
2217
2202
|
import_core7.HTTP.OK,
|
|
@@ -2248,12 +2233,11 @@ function userController(store, config, bus) {
|
|
|
2248
2233
|
const userId = ctx.user.id;
|
|
2249
2234
|
await users.softDelete(userId);
|
|
2250
2235
|
const reqId = ctx.meta["requestId"];
|
|
2251
|
-
bus?.emit(
|
|
2236
|
+
await (0, import_core7.background)(bus?.emit(
|
|
2252
2237
|
EVENT_KEYS.userDeleted,
|
|
2253
2238
|
{ userId },
|
|
2254
2239
|
reqId !== void 0 ? { requestId: reqId } : void 0
|
|
2255
|
-
)
|
|
2256
|
-
});
|
|
2240
|
+
));
|
|
2257
2241
|
return Response.json(
|
|
2258
2242
|
{ reason: "ACCOUNT_DELETED", explanation: "Account successfully deleted." },
|
|
2259
2243
|
{
|