session-sync-auth-site 3.0.4 → 3.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "session-sync-auth-site",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "main": "src/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,11 +21,7 @@ const authenticate = ({
21
21
  }
22
22
 
23
23
  // Connect to DB if not already connected
24
- if(!global.sessionSyncAuthSiteConnection) {
25
- console.log('Establishing DB connection for session-sync-auth-site...')
26
- await setUpConnection(connectionInfo)
27
- console.log('...DB connection established for session-sync-auth-site.')
28
- }
24
+ await setUpConnection(connectionInfo)
29
25
 
30
26
  let accessToken = req.headers['x-access-token']
31
27
 
@@ -6,20 +6,36 @@ const setUpConnection = async ({
6
6
  connectionObj,
7
7
  }={}) => {
8
8
 
9
- connectionObj = connectionObj || new ConnectionString(connectionStr)
10
-
11
- global.sessionSyncAuthSiteConnection = await mysql.createConnection({
12
- multipleStatements: true,
13
- dateStrings: true,
14
- charset : 'utf8mb4',
15
- // debug: true,
16
- host: connectionObj.host || connectionObj.hosts[0].name,
17
- user: connectionObj.user || connectionObj.username,
18
- password: connectionObj.password,
19
- database: connectionObj.database || connectionObj.path[0],
20
- port: connectionObj.port,
21
- namedPlaceholders: true,
22
- })
9
+ if(global.sessionSyncAuthSiteConnection) return
10
+
11
+ if(!global.sessionSyncAuthSiteConnectionPromise) {
12
+
13
+ global.sessionSyncAuthSiteConnectionPromise = (async () => {
14
+
15
+ console.log('Establishing DB connection for session-sync-auth-site...')
16
+
17
+ connectionObj = connectionObj || new ConnectionString(connectionStr)
18
+
19
+ global.sessionSyncAuthSiteConnection = await mysql.createConnection({
20
+ multipleStatements: true,
21
+ dateStrings: true,
22
+ charset : 'utf8mb4',
23
+ // debug: true,
24
+ host: connectionObj.host || connectionObj.hosts[0].name,
25
+ user: connectionObj.user || connectionObj.username,
26
+ password: connectionObj.password,
27
+ database: connectionObj.database || connectionObj.path[0],
28
+ port: connectionObj.port,
29
+ namedPlaceholders: true,
30
+ })
31
+
32
+ console.log('...DB connection established for session-sync-auth-site.')
33
+
34
+ })()
35
+
36
+ }
37
+
38
+ await global.sessionSyncAuthSiteConnectionPromise
23
39
 
24
40
  }
25
41