We are tying to authenticate the web3auth JWT Token (idToken) generated at frontend on the backend server using jose, we were verifying the same token to authenticate the genuine user and get payload details.
const jwks = jose.createRemoteJWKSet(new URL("https://api-auth.web3auth.io/jwks"));
while working on the localsystem the code snippet worked as expected and generated the write payload details, but when pushing the same code online to servers. the above mentioned code line throws the following error:
Error: Cannot set headers after they are sent to the client
1|backend | at new NodeError (node:internal/errors:387:5)
1|backend | at ServerResponse.setHeader (node:_http_outgoing:644:11)
1|backend | at ServerResponse.header (/home/ubuntu/lighthouse-backend/node_modules/express/lib/response.js:794:10)
1|backend | at ServerResponse.send (/home/ubuntu/lighthouse-backend/node_modules/express/lib/response.js:174:12)
1|backend | at ServerResponse.json (/home/ubuntu/lighthouse-backend/node_modules/express/lib/response.js:278:15)
1|backend | at ServerResponse.send (/home/ubuntu/lighthouse-backend/node_modules/express/lib/response.js:162:21)
1|backend | at exports.default (/home/ubuntu/lighthouse-backend/src/middlewares/error-handler.ts:8:19)
1|backend | at Layer.handle_error (/home/ubuntu/lighthouse-backend/node_modules/express/lib/router/layer.js:71:5)
1|backend | at trim_prefix (/home/ubuntu/lighthouse-backend/node_modules/express/lib/router/index.js:326:13)
1|backend | at /home/ubuntu/lighthouse-backend/node_modules/express/lib/router/index.js:286:9
Please suggest , How this can be fixed ?