@7365admin1/core 3.125.1-staging.419 → 3.125.1-staging.420
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/.changeset/last-login-field.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/last-login.e2e.test.mjs +127 -0
- package/test/e2e/service-provider-subcontract.e2e.test.mjs +8 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
"Last active": every session issued (web sign-in, mobile sign-in, mobile session refresh) stamps `users.lastLoginAt` without awaiting it, so a failed write never blocks or slows a sign-in. `GET /api/members` and `GET /api/service-providers/site-members` return `lastLoginAt` per person (absent/null until their next sign-in; no backfill).
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,8 @@ type TUser = {
|
|
|
119
119
|
defaultOrg?: string | ObjectId;
|
|
120
120
|
status?: string;
|
|
121
121
|
sid?: string;
|
|
122
|
+
/** Last time a session was issued (sign-in or mobile session refresh). Shown as "Last active". */
|
|
123
|
+
lastLoginAt?: Date;
|
|
122
124
|
block?: string | ObjectId | null;
|
|
123
125
|
level?: string | ObjectId | null;
|
|
124
126
|
type?: string;
|
|
@@ -214,6 +216,7 @@ declare function useUserRepo(): {
|
|
|
214
216
|
updateDefaultOrgByEmail: (email: string, value: string, session?: ClientSession) => Promise<string>;
|
|
215
217
|
getUserByEmailStatus: (email: string) => Promise<TUser | null>;
|
|
216
218
|
updateUserSIDById: (id: string | ObjectId, sid: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
219
|
+
recordLastLogin: (id: string | ObjectId) => Promise<void>;
|
|
217
220
|
resetPassword: ({ _id, password, sid, }: {
|
|
218
221
|
_id: string | ObjectId;
|
|
219
222
|
password: string;
|
package/dist/index.js
CHANGED
|
@@ -4157,6 +4157,9 @@ function useUserRepo() {
|
|
|
4157
4157
|
throw new import_node_server_utils12.InternalServerError("Failed to update user.");
|
|
4158
4158
|
}
|
|
4159
4159
|
}
|
|
4160
|
+
async function recordLastLogin(id) {
|
|
4161
|
+
await collection.updateOne({ _id: (0, import_node_server_utils12.toObjectId)(id) }, { $set: { lastLoginAt: /* @__PURE__ */ new Date() } });
|
|
4162
|
+
}
|
|
4160
4163
|
async function updateUserOrgById(id, org, session) {
|
|
4161
4164
|
const _id = (0, import_node_server_utils12.toObjectId)(id);
|
|
4162
4165
|
const orgId = (0, import_node_server_utils12.toObjectId)(org);
|
|
@@ -4318,6 +4321,7 @@ function useUserRepo() {
|
|
|
4318
4321
|
updateDefaultOrgByEmail,
|
|
4319
4322
|
getUserByEmailStatus,
|
|
4320
4323
|
updateUserSIDById,
|
|
4324
|
+
recordLastLogin,
|
|
4321
4325
|
resetPassword,
|
|
4322
4326
|
updateUserOrgById,
|
|
4323
4327
|
updateUserUnitById
|
|
@@ -4942,7 +4946,7 @@ function useMemberRepo() {
|
|
|
4942
4946
|
localField: "user",
|
|
4943
4947
|
foreignField: "_id",
|
|
4944
4948
|
as: "users",
|
|
4945
|
-
pipeline: [{ $project: { email: 1 } }]
|
|
4949
|
+
pipeline: [{ $project: { email: 1, lastLoginAt: 1 } }]
|
|
4946
4950
|
}
|
|
4947
4951
|
},
|
|
4948
4952
|
{ $unwind: { path: "$users", preserveNullAndEmptyArrays: true } },
|
|
@@ -4951,6 +4955,7 @@ function useMemberRepo() {
|
|
|
4951
4955
|
name: 1,
|
|
4952
4956
|
email: { $ifNull: ["$email", "$users.email"] },
|
|
4953
4957
|
user: 1,
|
|
4958
|
+
lastLoginAt: "$users.lastLoginAt",
|
|
4954
4959
|
roleName: "$roles.name",
|
|
4955
4960
|
role: "$roles._id",
|
|
4956
4961
|
// Whether roleName is a role this member can really use, so the
|
|
@@ -5836,7 +5841,8 @@ function useAuthService() {
|
|
|
5836
5841
|
const {
|
|
5837
5842
|
getUserByEmail,
|
|
5838
5843
|
getUserById: _getUserById,
|
|
5839
|
-
updateUserSIDById: _updateUserSIDById
|
|
5844
|
+
updateUserSIDById: _updateUserSIDById,
|
|
5845
|
+
recordLastLogin
|
|
5840
5846
|
} = useUserRepo();
|
|
5841
5847
|
const {
|
|
5842
5848
|
createFamily: _createFamily,
|
|
@@ -5855,6 +5861,7 @@ function useAuthService() {
|
|
|
5855
5861
|
const updatedUser = await _getUserById(userId);
|
|
5856
5862
|
assertAccountLive(updatedUser?.status);
|
|
5857
5863
|
await rememberSession(userId, sid);
|
|
5864
|
+
recordLastLogin(userId).catch((error) => console.error("Error recording last login:", error));
|
|
5858
5865
|
setCache(cacheKey, updatedUser, SESSION_TTL).then(() => {
|
|
5859
5866
|
console.log("Session ID cached successfully");
|
|
5860
5867
|
}).catch((error) => {
|
|
@@ -13683,7 +13690,7 @@ function useServiceProviderRepo() {
|
|
|
13683
13690
|
localField: "user",
|
|
13684
13691
|
foreignField: "_id",
|
|
13685
13692
|
as: "_user",
|
|
13686
|
-
pipeline: [{ $project: { email: 1, name: 1 } }]
|
|
13693
|
+
pipeline: [{ $project: { email: 1, name: 1, lastLoginAt: 1 } }]
|
|
13687
13694
|
}
|
|
13688
13695
|
},
|
|
13689
13696
|
{
|
|
@@ -13709,7 +13716,8 @@ function useServiceProviderRepo() {
|
|
|
13709
13716
|
email: {
|
|
13710
13717
|
$ifNull: [{ $arrayElemAt: ["$_user.email", 0] }, "$email"]
|
|
13711
13718
|
},
|
|
13712
|
-
roleName: { $ifNull: [{ $arrayElemAt: ["$_role.name", 0] }, ""] }
|
|
13719
|
+
roleName: { $ifNull: [{ $arrayElemAt: ["$_role.name", 0] }, ""] },
|
|
13720
|
+
lastLoginAt: { $arrayElemAt: ["$_user.lastLoginAt", 0] }
|
|
13713
13721
|
}
|
|
13714
13722
|
}
|
|
13715
13723
|
]).toArray();
|
|
@@ -36326,6 +36334,7 @@ function useServiceProviderService() {
|
|
|
36326
36334
|
role: m.roleName ?? "",
|
|
36327
36335
|
status: m.status ?? "active",
|
|
36328
36336
|
addedAt: m.createdAt ?? null,
|
|
36337
|
+
lastLoginAt: m.lastLoginAt ?? null,
|
|
36329
36338
|
invitedVia: company.invitedVia ?? ""
|
|
36330
36339
|
};
|
|
36331
36340
|
});
|
|
@@ -99885,6 +99894,7 @@ var SESSION_TTL2 = 14400;
|
|
|
99885
99894
|
var REFRESH_TOKEN_TTL2 = 7 * 24 * 60 * 60;
|
|
99886
99895
|
function useAuthServiceV2() {
|
|
99887
99896
|
const { getUserByEmail, getUserById: _getUserById } = useUserRepoV2();
|
|
99897
|
+
const { recordLastLogin } = useUserRepo();
|
|
99888
99898
|
const {
|
|
99889
99899
|
createFamily: _createFamily,
|
|
99890
99900
|
findActiveByToken: _findActiveByToken,
|
|
@@ -99901,6 +99911,8 @@ function useAuthServiceV2() {
|
|
|
99901
99911
|
const cacheKey = `sid:${sid}`;
|
|
99902
99912
|
const { password: _password, ...safeUser } = user;
|
|
99903
99913
|
await rememberSession(user?._id, sid);
|
|
99914
|
+
if (user?._id)
|
|
99915
|
+
recordLastLogin(user._id).catch((error) => console.error("Error recording last login:", error));
|
|
99904
99916
|
setCache(cacheKey, safeUser, SESSION_TTL2).then(() => {
|
|
99905
99917
|
console.log("Session ID cached successfully");
|
|
99906
99918
|
}).catch((error) => {
|