Skip to content

Commit db1b5b9

Browse files
author
sachin-maheshwari
authored
Update helper.js
changes required to avoid excess auth0 calls.
1 parent 9030099 commit db1b5b9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/common/helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
const m2mAuth = require('tc-core-library-js').auth.m2m
33
const request = require('superagent')
44
const _ = require('lodash')
5+
var m2m = null
56

67
/*
78
* Function to get M2M token
89
* @returns {Promise}
910
*/
1011
const getM2Mtoken = async (config) => {
11-
const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL']))
12+
if (_.isNull(m2m)) {
13+
m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL']))
14+
}
1215
return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
1316
}
1417

0 commit comments

Comments
 (0)