Browse Source

updateTokenEnv maj

niemes 2 years ago
parent
commit
66e06c9f89
1 changed files with 8 additions and 11 deletions
  1. 8 11
      index.js

+ 8 - 11
index.js

@@ -37,6 +37,10 @@ jsonfile.readFile(tokenFile, function (err, obj) {
 function updateTokenEnv(data){
 
     let reqObj = data
+    info.token = reqObj
+    info.authorized = true;
+    info.active = true
+
     console.log("[updateTokenEnv] :");
     console.log(data);
     jsonfile.writeFile(tokenFile, reqObj, function (err) {
@@ -64,9 +68,8 @@ async function watchLinkedin(){
                 // try refresh token 
                 const data = await API.getAccessToken(info.token)
 
-                if(data.access_token) {
-                    mail.notif();
-                }
+                if(!data.access_token) mail.notif();
+                else 
             }
         });
     }
@@ -94,14 +97,8 @@ app.get('/callback', async (req, res) => {
     }
     try {
         const data = await API.getAccessToken(req.query.code);
-        if(data.access_token) {
-            info.token = data.access_token;
-            info.authorized = true;
-            info.active = true
-            process.env.access_token = info.token
-            process.env.expire = data.expire ? data.expire : 0
-            updateTokenEnv(data)
-        }
+        if(data.access_token) updateTokenEnv(data)
+        
         res.redirect('/');
     } catch(err) {
         res.json(err);