-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathattach.js
More file actions
34 lines (29 loc) · 875 Bytes
/
attach.js
File metadata and controls
34 lines (29 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const get = require('lodash/get');
const UserMetadata = require('../../../utils/metadata/user');
const handlePipeline = require('../../../utils/pipeline-error');
const {
USERS_SSO_TO_ID,
} = require('../../../constants');
module.exports = async function attach(account, user) {
const { redis, config } = this;
const { id: userId } = user;
const {
uid, provider, internals, profile,
} = account;
const audience = get(config, 'jwt.defaultAudience');
const pipeline = this.userData.attachProvider(userId, provider, internals);
// link uid to user id
pipeline.hset(USERS_SSO_TO_ID, uid, userId);
handlePipeline(await pipeline.exec());
const updateParams = {
metadata: {
$set: {
[provider]: profile,
},
},
};
await UserMetadata
.using(userId, audience, redis)
.batchUpdate(updateParams);
return profile;
};