@abtnode/blocklet-services 1.16.18-beta-adeeb0b3 → 1.16.18-beta-aa01bd8e
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/api/index.js +1 -0
- package/api/libs/connect/session.js +45 -33
- package/api/middlewares/check-running.js +1 -1
- package/api/routes/blocklet.js +18 -0
- package/api/routes/federated.js +10 -9
- package/api/routes/oauth.js +79 -60
- package/api/routes/user-session.js +23 -16
- package/api/routes/user.js +160 -22
- package/api/services/auth/connect/invite.js +21 -12
- package/api/util/federated.js +13 -12
- package/api/validators/login.js +12 -0
- package/build/asset-manifest.json +100 -80
- package/build/index.html +1 -1
- package/build/service-worker.js +1 -1
- package/build/service-worker.js.map +1 -1
- package/build/static/css/{807.65f26433.chunk.css → 4448.de9040c4.chunk.css} +1 -1
- package/build/static/js/1.138935fc.chunk.js +2 -0
- package/build/static/js/{1148.4b2a7347.chunk.js → 1148.e614f706.chunk.js} +2 -2
- package/build/static/js/1343.69031e0b.chunk.js +2 -0
- package/build/static/js/1581.ed4544c6.chunk.js +2 -0
- package/build/static/js/2026.514f995a.chunk.js +2 -0
- package/build/static/js/{2291.7ffdc7df.chunk.js → 2291.37b0ad3a.chunk.js} +2 -2
- package/build/static/js/{3490.4d3a51ea.chunk.js → 2362.ab5308a8.chunk.js} +2 -2
- package/build/static/js/2506.dd9284b6.chunk.js +2 -0
- package/build/static/js/{2838.fcdea2fa.chunk.js → 2838.ec459fda.chunk.js} +3 -3
- package/build/static/js/{3025.a48c96f5.chunk.js → 3025.aa129833.chunk.js} +2 -2
- package/build/static/js/3076.28658ffc.chunk.js +2 -0
- package/build/static/js/3683.6f169a32.chunk.js +2 -0
- package/build/static/js/3920.5c63a2b9.chunk.js +3 -0
- package/build/static/js/3979.f9a5aa48.chunk.js +3 -0
- package/build/static/js/{807.249d2d01.chunk.js.LICENSE.txt → 3979.f9a5aa48.chunk.js.LICENSE.txt} +0 -18
- package/build/static/js/3994.e53e7ce2.chunk.js +2 -0
- package/build/static/js/4009.65d1c083.chunk.js +2 -0
- package/build/static/js/{4023.1658794f.chunk.js → 4023.a2e9db00.chunk.js} +2 -2
- package/build/static/js/4247.c25f1945.chunk.js +2 -0
- package/build/static/js/{4319.8d9e189e.chunk.js → 4319.9f120992.chunk.js} +2 -2
- package/build/static/js/4448.f0c62086.chunk.js +3 -0
- package/build/static/js/4448.f0c62086.chunk.js.LICENSE.txt +17 -0
- package/build/static/js/4461.26253c6a.chunk.js +2 -0
- package/build/static/js/4802.cd83ecef.chunk.js +2 -0
- package/build/static/js/4882.0435e418.chunk.js +2 -0
- package/build/static/js/5547.8447edf9.chunk.js +3 -0
- package/build/static/js/556.4d5cc702.chunk.js +3 -0
- package/build/static/js/{5683.47011724.chunk.js → 5683.051a03c1.chunk.js} +2 -2
- package/build/static/js/6032.48c0a152.chunk.js +2 -0
- package/build/static/js/6139.5867193a.chunk.js +2 -0
- package/build/static/js/655.cdee65b4.chunk.js +2 -0
- package/build/static/js/{6771.a1510398.chunk.js → 6771.920fa5b6.chunk.js} +3 -3
- package/build/static/js/7006.bb90b167.chunk.js +2 -0
- package/build/static/js/779.383b4b4a.chunk.js +2 -0
- package/build/static/js/{7832.741ac84f.chunk.js → 7832.81aaf011.chunk.js} +2 -2
- package/build/static/js/{7858.e4167dfd.chunk.js → 7858.4e5b7c88.chunk.js} +2 -2
- package/build/static/js/8181.86477cc5.chunk.js +2 -0
- package/build/static/js/8604.ece06cf7.chunk.js +3 -0
- package/build/static/js/{8622.f9639db9.chunk.js → 8622.66a81bc0.chunk.js} +2 -2
- package/build/static/js/8944.07bcf75f.chunk.js +2 -0
- package/build/static/js/8983.19b79a23.chunk.js +2 -0
- package/build/static/js/9017.56c20b17.chunk.js +2 -0
- package/build/static/js/9582.2c539fcf.chunk.js +2 -0
- package/build/static/js/9880.13ac9520.chunk.js +2 -0
- package/build/static/js/9996.5545ea26.chunk.js +2 -0
- package/build/static/js/main.63103d24.js +3 -0
- package/build/static/js/{main.50d5cec4.js.LICENSE.txt → main.63103d24.js.LICENSE.txt} +1 -1
- package/package.json +34 -34
- package/build/static/js/1431.29b0bc0a.chunk.js +0 -3
- package/build/static/js/2093.3ce9b59d.chunk.js +0 -3
- package/build/static/js/2686.890b32ed.chunk.js +0 -2
- package/build/static/js/4022.5ec79b56.chunk.js +0 -2
- package/build/static/js/4461.f412553b.chunk.js +0 -2
- package/build/static/js/4802.fe56c787.chunk.js +0 -2
- package/build/static/js/5465.dd0f7a20.chunk.js +0 -2
- package/build/static/js/5547.5a341867.chunk.js +0 -3
- package/build/static/js/5662.03f06ae0.chunk.js +0 -2
- package/build/static/js/5673.0dd67df6.chunk.js +0 -2
- package/build/static/js/5960.35db200d.chunk.js +0 -2
- package/build/static/js/6139.cabc22a2.chunk.js +0 -2
- package/build/static/js/6498.698608f8.chunk.js +0 -2
- package/build/static/js/6868.881bd141.chunk.js +0 -2
- package/build/static/js/7006.8f0645e5.chunk.js +0 -2
- package/build/static/js/7367.15383006.chunk.js +0 -2
- package/build/static/js/779.b64e7db1.chunk.js +0 -2
- package/build/static/js/807.249d2d01.chunk.js +0 -3
- package/build/static/js/8604.a8ef404e.chunk.js +0 -3
- package/build/static/js/8641.506d61d5.chunk.js +0 -2
- package/build/static/js/8944.2d60df14.chunk.js +0 -2
- package/build/static/js/main.50d5cec4.js +0 -3
- /package/build/static/js/{2838.fcdea2fa.chunk.js.LICENSE.txt → 2838.ec459fda.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{2093.3ce9b59d.chunk.js.LICENSE.txt → 3920.5c63a2b9.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{5547.5a341867.chunk.js.LICENSE.txt → 5547.8447edf9.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{1431.29b0bc0a.chunk.js.LICENSE.txt → 556.4d5cc702.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{6771.a1510398.chunk.js.LICENSE.txt → 6771.920fa5b6.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{8604.a8ef404e.chunk.js.LICENSE.txt → 8604.ece06cf7.chunk.js.LICENSE.txt} +0 -0
package/api/index.js
CHANGED
|
@@ -118,6 +118,7 @@ module.exports = function createServer(node, serverOptions = {}) {
|
|
|
118
118
|
BlockletEvents.removed,
|
|
119
119
|
BlockletEvents.statusChange,
|
|
120
120
|
BlockletEvents.installed,
|
|
121
|
+
BlockletEvents.componentRemoved,
|
|
121
122
|
].forEach((name) => {
|
|
122
123
|
eventHub.on(name, (data) => {
|
|
123
124
|
const did = get(data, 'meta.did');
|
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
getPassportStatusEndpoint,
|
|
11
11
|
getApplicationInfo,
|
|
12
12
|
verifyNFT,
|
|
13
|
-
upsertUserSession,
|
|
14
13
|
} = require('@abtnode/auth/lib/auth');
|
|
15
14
|
const {
|
|
16
15
|
NODE_SERVICES,
|
|
@@ -409,38 +408,51 @@ module.exports = {
|
|
|
409
408
|
node
|
|
410
409
|
);
|
|
411
410
|
}
|
|
411
|
+
const lastLoginIp = request.headers['x-real-ip'];
|
|
412
|
+
const ua = request.headers['user-agent'];
|
|
412
413
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
avatar: getUserAvatarUrl(updatedUser.avatar, blocklet),
|
|
424
|
-
connectedAccount: [connectAccount, connectedNft],
|
|
425
|
-
action: 'connectAccount',
|
|
426
|
-
sourceAppPid: sourceAppPid || masterSite.appPid,
|
|
427
|
-
},
|
|
428
|
-
],
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
}
|
|
414
|
+
const userSessionDoc = await node.upsertUserSession({
|
|
415
|
+
teamDid,
|
|
416
|
+
visitorId,
|
|
417
|
+
userDid: realDid,
|
|
418
|
+
appPid: teamDid,
|
|
419
|
+
passportId: passport?.id,
|
|
420
|
+
status: 'online',
|
|
421
|
+
ua,
|
|
422
|
+
lastLoginIp,
|
|
423
|
+
});
|
|
432
424
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
425
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
426
|
+
node
|
|
427
|
+
.syncFederated({
|
|
428
|
+
did: teamDid,
|
|
429
|
+
data: {
|
|
430
|
+
users: [
|
|
431
|
+
{
|
|
432
|
+
did: updatedUser.did,
|
|
433
|
+
pk: updatedUser.pk,
|
|
434
|
+
fullName: updatedUser.fullName,
|
|
435
|
+
email: updatedUser.email || '',
|
|
436
|
+
avatar: getUserAvatarUrl(updatedUser.avatar, blocklet),
|
|
437
|
+
connectedAccount: [connectAccount, connectedNft],
|
|
438
|
+
action: 'connectAccount',
|
|
439
|
+
sourceAppPid: sourceAppPid || masterSite.appPid,
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
},
|
|
443
|
+
})
|
|
444
|
+
.then(() => {
|
|
445
|
+
node.syncUserSession({
|
|
446
|
+
teamDid,
|
|
447
|
+
userDid: realDid,
|
|
448
|
+
visitorId: userSessionDoc.visitorId,
|
|
449
|
+
passportId: passport?.id,
|
|
450
|
+
targetAppPid: sourceAppPid,
|
|
451
|
+
ua,
|
|
452
|
+
lastLoginIp,
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
444
456
|
|
|
445
457
|
// Generate new session token that client can save to localStorage
|
|
446
458
|
const createToken = createTokenFn(createSessionToken);
|
|
@@ -586,7 +598,7 @@ module.exports = {
|
|
|
586
598
|
const sourceAppPid = getSourceAppPid(request);
|
|
587
599
|
const masterSite = getFederatedMaster(blocklet);
|
|
588
600
|
// NOTICE: 采用异步来更新,不阻塞接口的正常响应
|
|
589
|
-
if (shouldSyncFederated(sourceAppPid,
|
|
601
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
590
602
|
node.syncFederated({
|
|
591
603
|
did: teamDid,
|
|
592
604
|
data: {
|
|
@@ -914,7 +926,7 @@ module.exports = {
|
|
|
914
926
|
});
|
|
915
927
|
const masterSite = getFederatedMaster(blocklet);
|
|
916
928
|
// NOTICE: 采用异步来更新,不阻塞接口的正常响应
|
|
917
|
-
if (shouldSyncFederated(sourceAppPid,
|
|
929
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
918
930
|
const syncUserData = {
|
|
919
931
|
did: oauthUser.did,
|
|
920
932
|
pk: oauthUser.pk,
|
|
@@ -34,7 +34,7 @@ const checkRunning = async (req, res, next) => {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const nodeInfo = await req.getNodeInfo();
|
|
37
|
-
res.status(
|
|
37
|
+
res.status(503);
|
|
38
38
|
// return json if json has high priority, e.g. "*/*,application/json"
|
|
39
39
|
if (req.accepts(['html', 'json']) === 'json') {
|
|
40
40
|
res.json({ code: 'error', error: 'blocklet is under maintenance' });
|
package/api/routes/blocklet.js
CHANGED
|
@@ -30,6 +30,7 @@ const {
|
|
|
30
30
|
wipeSensitiveData,
|
|
31
31
|
findComponentByIdV2,
|
|
32
32
|
forEachComponentV2Sync,
|
|
33
|
+
hasResourceType,
|
|
33
34
|
} = require('@blocklet/meta/lib/util');
|
|
34
35
|
const {
|
|
35
36
|
WELLKNOWN_SERVICE_PATH_PREFIX,
|
|
@@ -517,5 +518,22 @@ module.exports = {
|
|
|
517
518
|
res.status(500).send(err.message);
|
|
518
519
|
}
|
|
519
520
|
});
|
|
521
|
+
|
|
522
|
+
server.get(`${prefix}/api/resources`, checkAdminPermission, async (req, res) => {
|
|
523
|
+
const { resourceType } = req.query;
|
|
524
|
+
const blocklet = await req.getBlocklet();
|
|
525
|
+
|
|
526
|
+
const components = (blocklet.children || []).filter((x) => hasResourceType(x, resourceType));
|
|
527
|
+
|
|
528
|
+
const resources = components.map((x) => ({
|
|
529
|
+
did: x.meta.did,
|
|
530
|
+
title: x.meta.title,
|
|
531
|
+
description: x.meta.description,
|
|
532
|
+
version: x.meta.version,
|
|
533
|
+
logo: `${prefix}/blocklet/logo-bundle/${x.meta.did}?v=${x.meta.version}`,
|
|
534
|
+
}));
|
|
535
|
+
|
|
536
|
+
res.json(resources);
|
|
537
|
+
});
|
|
520
538
|
},
|
|
521
539
|
};
|
package/api/routes/federated.js
CHANGED
|
@@ -315,11 +315,11 @@ module.exports = {
|
|
|
315
315
|
const { users = null, sites = null, userSessions = null } = req.body.verifyData;
|
|
316
316
|
|
|
317
317
|
// FIXME: @zhanghan 校验 users 和 sites 数据合法性
|
|
318
|
-
const pendingList = [];
|
|
319
318
|
if (!isNil(sites)) {
|
|
319
|
+
const pendingSiteList = [];
|
|
320
320
|
const federated = cloneDeep(blocklet.settings.federated || {});
|
|
321
321
|
federated.sites = sites;
|
|
322
|
-
|
|
322
|
+
pendingSiteList.push(
|
|
323
323
|
limitSync(async () => {
|
|
324
324
|
await node.setFederated({
|
|
325
325
|
did: teamDid,
|
|
@@ -327,14 +327,16 @@ module.exports = {
|
|
|
327
327
|
});
|
|
328
328
|
})
|
|
329
329
|
);
|
|
330
|
+
await Promise.all(pendingSiteList);
|
|
330
331
|
}
|
|
331
332
|
|
|
332
333
|
if (!isNil(users)) {
|
|
333
334
|
if (Array.isArray(users)) {
|
|
335
|
+
const pendingUserList = [];
|
|
334
336
|
const nodeInfo = await req.getNodeInfo();
|
|
335
337
|
const { dataDir } = await getApplicationInfo({ node, nodeInfo, teamDid });
|
|
336
338
|
for (const user of users) {
|
|
337
|
-
|
|
339
|
+
pendingUserList.push(
|
|
338
340
|
limitSync(async () => {
|
|
339
341
|
await syncFnMaps[user.action]?.(
|
|
340
342
|
{ ...user, sourceAppPid: user.sourceAppPid === teamDid ? undefined : user.sourceAppPid },
|
|
@@ -343,30 +345,29 @@ module.exports = {
|
|
|
343
345
|
})
|
|
344
346
|
);
|
|
345
347
|
}
|
|
348
|
+
await Promise.all(pendingUserList);
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
351
|
|
|
349
352
|
if (!isNil(userSessions)) {
|
|
350
353
|
if (Array.isArray(userSessions)) {
|
|
354
|
+
const pendingUserSessionList = [];
|
|
351
355
|
for (const userSession of userSessions) {
|
|
352
356
|
const { action, ...userSessionItem } = userSession;
|
|
353
|
-
|
|
357
|
+
pendingUserSessionList.push(
|
|
354
358
|
limitSync(async () => {
|
|
355
359
|
if (action === 'login') {
|
|
356
|
-
await node.upsertUserSession(
|
|
357
|
-
{ ...userSessionItem, teamDid, status: 'online' },
|
|
358
|
-
{ req, node, sourceAppPid: teamDid }
|
|
359
|
-
);
|
|
360
|
+
await node.upsertUserSession({ ...userSessionItem, teamDid, status: 'online' });
|
|
360
361
|
} else if (action === 'logout') {
|
|
361
362
|
await node.logoutUser({ ...userSessionItem, teamDid });
|
|
362
363
|
}
|
|
363
364
|
})
|
|
364
365
|
);
|
|
365
366
|
}
|
|
367
|
+
await Promise.all(pendingUserSessionList);
|
|
366
368
|
}
|
|
367
369
|
}
|
|
368
370
|
|
|
369
|
-
await Promise.all(pendingList);
|
|
370
371
|
await node.createAuditLog(
|
|
371
372
|
{
|
|
372
373
|
action: 'syncFederated',
|
package/api/routes/oauth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { handleInvitationReceive, getApplicationInfo
|
|
1
|
+
const { handleInvitationReceive, getApplicationInfo } = require('@abtnode/auth/lib/auth');
|
|
2
2
|
const { upsertToPassports, createPassportSvg } = require('@abtnode/auth/lib/passport');
|
|
3
3
|
const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_SERVICES, PASSPORT_STATUS } = require('@abtnode/constant');
|
|
4
4
|
const { extractUserAvatar, getUserAvatarUrl, getAppAvatarUrl } = require('@abtnode/util/lib/user');
|
|
@@ -187,7 +187,19 @@ async function login(req, node, options) {
|
|
|
187
187
|
);
|
|
188
188
|
|
|
189
189
|
const masterSite = getFederatedMaster(blocklet);
|
|
190
|
-
|
|
190
|
+
const ua = req.headers['user-agent'];
|
|
191
|
+
const userSessionDoc = await node.upsertUserSession({
|
|
192
|
+
teamDid,
|
|
193
|
+
userDid: currentUser.did,
|
|
194
|
+
visitorId,
|
|
195
|
+
appPid: teamDid,
|
|
196
|
+
passportId: passport?.id,
|
|
197
|
+
status: 'online',
|
|
198
|
+
ua,
|
|
199
|
+
lastLoginIp,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
191
203
|
const syncUserData = {
|
|
192
204
|
did: userDid,
|
|
193
205
|
pk: userPk,
|
|
@@ -195,35 +207,32 @@ async function login(req, node, options) {
|
|
|
195
207
|
avatar: getUserAvatarUrl(appUrl, profile.avatar),
|
|
196
208
|
connectedAccount: [connectedAccount],
|
|
197
209
|
};
|
|
198
|
-
await node.syncFederated({
|
|
199
|
-
did: teamDid,
|
|
200
|
-
data: {
|
|
201
|
-
users: [
|
|
202
|
-
{
|
|
203
|
-
...syncUserData,
|
|
204
|
-
action: 'connectAccount',
|
|
205
|
-
sourceAppPid: sourceAppPid || masterSite?.appPid,
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
210
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
211
|
+
node
|
|
212
|
+
.syncFederated({
|
|
213
|
+
did: teamDid,
|
|
214
|
+
data: {
|
|
215
|
+
users: [
|
|
216
|
+
{
|
|
217
|
+
...syncUserData,
|
|
218
|
+
action: 'connectAccount',
|
|
219
|
+
sourceAppPid: sourceAppPid || masterSite?.appPid,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
})
|
|
224
|
+
.then(() => {
|
|
225
|
+
node.syncUserSession({
|
|
226
|
+
teamDid,
|
|
227
|
+
userDid: currentUser.did,
|
|
228
|
+
visitorId: userSessionDoc.visitorId,
|
|
229
|
+
passportId: passport?.id,
|
|
230
|
+
targetAppPid: sourceAppPid,
|
|
231
|
+
ua,
|
|
232
|
+
lastLoginIp,
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
227
236
|
|
|
228
237
|
const { createSessionToken } = initJwt(node, options);
|
|
229
238
|
|
|
@@ -329,6 +338,9 @@ async function invite(req, node, options) {
|
|
|
329
338
|
provider,
|
|
330
339
|
});
|
|
331
340
|
const masterSite = getFederatedMaster(blocklet);
|
|
341
|
+
const syncData = {
|
|
342
|
+
users: [],
|
|
343
|
+
};
|
|
332
344
|
|
|
333
345
|
if (currentUser) {
|
|
334
346
|
const walletDid = getWalletDid(currentUser);
|
|
@@ -368,28 +380,51 @@ async function invite(req, node, options) {
|
|
|
368
380
|
sourceAppPid,
|
|
369
381
|
},
|
|
370
382
|
});
|
|
371
|
-
|
|
372
|
-
if (shouldSyncFederated(sourceAppPid, masterSite, blocklet)) {
|
|
383
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
373
384
|
const syncUserData = {
|
|
374
385
|
did: userDid,
|
|
375
386
|
pk: userPk,
|
|
376
387
|
...profile,
|
|
377
388
|
connectedAccount: [connectedAccount],
|
|
378
389
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
{
|
|
384
|
-
...syncUserData,
|
|
385
|
-
action: 'connectAccount',
|
|
386
|
-
sourceAppPid: sourceAppPid || masterSite?.appPid,
|
|
387
|
-
},
|
|
388
|
-
],
|
|
389
|
-
},
|
|
390
|
+
syncData.users.push({
|
|
391
|
+
...syncUserData,
|
|
392
|
+
action: 'connectAccount',
|
|
393
|
+
sourceAppPid: sourceAppPid || masterSite?.appPid,
|
|
390
394
|
});
|
|
391
395
|
}
|
|
392
396
|
}
|
|
397
|
+
const lastLoginIp = req.headers['x-real-ip'];
|
|
398
|
+
const ua = req.headers['user-agent'];
|
|
399
|
+
const userSessionDoc = await node.upsertUserSession({
|
|
400
|
+
teamDid,
|
|
401
|
+
userDid,
|
|
402
|
+
visitorId,
|
|
403
|
+
appPid: teamDid,
|
|
404
|
+
passportId: passport.id,
|
|
405
|
+
status: 'online',
|
|
406
|
+
ua,
|
|
407
|
+
lastLoginIp,
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
411
|
+
node
|
|
412
|
+
.syncFederated({
|
|
413
|
+
did: teamDid,
|
|
414
|
+
data: syncData,
|
|
415
|
+
})
|
|
416
|
+
.then(() => {
|
|
417
|
+
node.syncUserSession({
|
|
418
|
+
teamDid,
|
|
419
|
+
userDid,
|
|
420
|
+
visitorId: userSessionDoc.visitorId,
|
|
421
|
+
passportId: passport?.id,
|
|
422
|
+
targetAppPid: sourceAppPid,
|
|
423
|
+
ua,
|
|
424
|
+
lastLoginIp,
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
}
|
|
393
428
|
|
|
394
429
|
const { createSessionToken } = initJwt(node, options);
|
|
395
430
|
|
|
@@ -407,22 +442,6 @@ async function invite(req, node, options) {
|
|
|
407
442
|
return sessionToken;
|
|
408
443
|
}
|
|
409
444
|
|
|
410
|
-
const userSessionDoc = await upsertUserSession(
|
|
411
|
-
{
|
|
412
|
-
teamDid,
|
|
413
|
-
userDid,
|
|
414
|
-
visitorId,
|
|
415
|
-
appPid: teamDid,
|
|
416
|
-
passportId: passport.id,
|
|
417
|
-
status: 'online',
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
node,
|
|
421
|
-
req,
|
|
422
|
-
sourceAppPid: sourceAppPid || masterSite?.appPid,
|
|
423
|
-
}
|
|
424
|
-
);
|
|
425
|
-
|
|
426
445
|
return {
|
|
427
446
|
sessionToken,
|
|
428
447
|
refreshToken,
|
|
@@ -512,7 +531,7 @@ async function bind(req, node, options) {
|
|
|
512
531
|
});
|
|
513
532
|
|
|
514
533
|
const masterSite = getFederatedMaster(blocklet);
|
|
515
|
-
if (shouldSyncFederated(sourceAppPid,
|
|
534
|
+
if (shouldSyncFederated(sourceAppPid, blocklet)) {
|
|
516
535
|
// NOTICE: 采用异步来更新,不阻塞接口的正常响应
|
|
517
536
|
const syncUserData = {
|
|
518
537
|
did: bindUser.did,
|
|
@@ -6,7 +6,6 @@ const pick = require('lodash/pick');
|
|
|
6
6
|
const defaults = require('lodash/defaults');
|
|
7
7
|
const cloneDeep = require('lodash/cloneDeep');
|
|
8
8
|
const pLimit = require('p-limit');
|
|
9
|
-
const { upsertUserSession } = require('@abtnode/auth/lib/auth');
|
|
10
9
|
const logger = require('@abtnode/logger')('blocklet-services:user-session');
|
|
11
10
|
|
|
12
11
|
const ensureBlocklet = require('../middlewares/ensure-blocklet');
|
|
@@ -127,21 +126,29 @@ module.exports = {
|
|
|
127
126
|
site: memberSite,
|
|
128
127
|
});
|
|
129
128
|
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
129
|
+
const lastLoginIp = req.headers['x-real-ip'];
|
|
130
|
+
const ua = req.headers['user-agent'];
|
|
131
|
+
|
|
132
|
+
const userSessionDoc = await node.upsertUserSession({
|
|
133
|
+
teamDid,
|
|
134
|
+
userDid,
|
|
135
|
+
visitorId,
|
|
136
|
+
appPid,
|
|
137
|
+
passportId,
|
|
138
|
+
status: 'online',
|
|
139
|
+
ua,
|
|
140
|
+
lastLoginIp,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
node.syncUserSession({
|
|
144
|
+
teamDid,
|
|
145
|
+
userDid,
|
|
146
|
+
visitorId: userSessionDoc.visitorId,
|
|
147
|
+
passportId,
|
|
148
|
+
targetAppPid: appPid,
|
|
149
|
+
ua,
|
|
150
|
+
lastLoginIp,
|
|
151
|
+
});
|
|
145
152
|
|
|
146
153
|
logger.info('quick-login with', {
|
|
147
154
|
teamDid,
|