Pythe1337N / garmin-connect

Makes it simple to interface with Garmin Connect to get or set any data point.
MIT License
145 stars 59 forks source link

Failed to restore session (user hash doesn't match) #53

Closed Marius-brt closed 1 year ago

Marius-brt commented 1 year ago

Restoring session not working. I use garmin.config.json file

My code :

const { GarminConnect } = require("garmin-connect");
const { writeFileSync, readFileSync, existsSync } = require("fs");
const GCClient = new GarminConnect();

async function main() {
  if (existsSync("userInfo.json")) {
    const userInfoFile = readFileSync("userInfo.json", "utf8");
    console.log("Restore session");
    await GCClient.restoreOrLogin(JSON.parse(userInfoFile));
  } else {
    console.log("Login");
    await GCClient.login();
  }
  const userInfo = await GCClient.getUserInfo();
  console.log(userInfo);
  writeFileSync("userInfo.json", JSON.stringify(userInfo), "utf8");
}

main();

The error :

Error: Unable to restore session due to: Error: Unable to restore session, user hash do not match
    at GarminConnect.restore (F:\Projects\Websites\Dashboard\Garmin Test\node_modules\garmin-connect\dist\garmin\GarminConnect.js:142:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (F:\Projects\Websites\Dashboard\Garmin Test\index.js:11:5)
Marius-brt commented 1 year ago

Sorry I used userInfo instead of GCClient.sessionJson my bad