ElyaConrad / iCloud-API

Node API for Apple's iCloud services
1.18k stars 98 forks source link

There is a bug in main: self.loggedIn : 113 - leading to Cannot read property 'reminders' of undefined #83

Open paulroth3d opened 1 year ago

paulroth3d commented 1 year ago

TLDR; @MauriceConrad - can you please release a new version - as there is a bug on main.js:113 that is fixed in the repo - BUT NOT if anyone npm installs..


There is a bug in main.js:113

it seems it is FIXED in the repository, BUT NOT IN npm.

This is what you get on line 113 if you install apple-icloud

npm install --save apple-icloud

look at node_modules/apple-icloud/main.js, and you get this:

      self.loggedIn = (function() {
        //console.log(self.auth.cookies.length > 0, !!self.auth.token, self.account != {}, self.username === username);
        return (self.auth.cookies.length > 0 && self.auth.token && self.account != {} && username ? (self.username === username) : true);
      })();

note the final condition: && username ? (self.username === username) : true

this is wrong and needs to be: && (username ? (self.username === username) : false));

(missing the parentheses around the check - bypassing the && operator, and almost always returning true)

This appears fixed in the git repository

https://github.com/MauriceConrad/iCloud-API/blob/master/main.js#L115


This is actually the source of a NUMBER of issues:

https://github.com/MauriceConrad/iCloud-API/issues/64 https://github.com/MauriceConrad/iCloud-API/issues/71 https://github.com/MauriceConrad/iCloud-API/issues/53 https://github.com/MauriceConrad/iCloud-API/issues/47

and many others.

These - and many others - all come from myCloud.account being an empty object, and therefore none of the apis can be called.

The reason it is empty is because self.loggedIn is setting to true, and therefore the self.login on line 162 never fires.

Could you please release a new version to npm?

paulroth3d commented 1 year ago

Otherwise, for anyone else running into this, look in the node_modules/apple-icloud/main.js

and change this:

      // Now, validate the session with checking for important aspects that show that the session can be used to get data (e.g. there need to be a token, some cookies and account info)
      self.loggedIn = (function() {
        //console.log(self.auth.cookies.length > 0, !!self.auth.token, self.account != {}, self.username === username);
        return (self.auth.cookies.length > 0 && self.auth.token && self.account != {} && username ? (self.username === username) : true);
      })();

into this:

      // Now, validate the session with checking for important aspects that show that the session can be used to get data (e.g. there need to be a token, some cookies and account info)
      self.loggedIn = (function() {
        //console.log(self.auth.cookies.length > 0, !!self.auth.token, self.account != {}, self.username === username);
        return (self.auth.cookies.length > 0 && self.auth.token && self.account != {} && username ? ((self.username === username) : false));
      })();