I am trying to build a server that will populate Salesforce through a front end website using Express JS with JSForce library. However, every time the access token expired, it does not refresh by itself. The connection instructor already has refreshToken in it and I already did Oauth2 Flow. Below is the code to establish connection.
const _login = () => {
let conn = new jsforce.Connection(session);
conn.on('refresh', (accessToken, result) => {
console.log('here');
const newConnection = new jsforce.Connection({
accessToken,
instanceUrl: result.instance_url
});
process.env.ACCESS_TOKEN = accessToken;
console.log(accessToken);
conn = newConnection;
});
return conn;
};
Is there anything wrong? I put this function separated from app.js and import this function into a router file. Thank you for your help!