Kiina / MMM-trakt

A MagicMirror Module to show your upcoming tv shows from trakt.tv
MIT License
14 stars 2 forks source link

Can't authenticate if the first attempt expires #18

Open Menturan opened 5 years ago

Menturan commented 5 years ago

Description

If you don't activate your device within 10 minutes the authentication/authorization of the device (the MagicMirror) will expire. When it expires the module creates a token file which will be empty. This empty token file will be used in all other attempts which leads to Error: OAuth required.

This bug is probably what causes the problems in issue #17 .

Suggested solution

Logs

[20:11:17] - MMM-trakt - :  Trakt Access Code: 3EC1C65D
[20:11:47] - MMM-trakt - :  Trakt Access Code: A7D98CE3
[20:12:17] - MMM-trakt - :  Trakt Access Code: EF46560D
[20:12:47] - MMM-trakt - :  Trakt Access Code: 3C9637E6
[20:13:17] - MMM-trakt - :  Trakt Access Code: 197B5FB9
[20:13:47] - MMM-trakt - :  Trakt Access Code: 0D033DC5
[20:14:17] - MMM-trakt - :  Trakt Access Code: 3ACB08E7
[20:14:47] - MMM-trakt - :  Trakt Access Code: D7E19BA0
[20:15:17] - MMM-trakt - :  Trakt Access Code: DD60D848
[20:15:47] - MMM-trakt - :  Trakt Access Code: 3A9190CD
[20:16:17] - MMM-trakt - :  Trakt Access Code: 6540D429
[20:16:47] - MMM-trakt - :  Trakt Access Code: 8A132FDB
[20:17:17] - MMM-trakt - :  Trakt Access Code: B14461DC
[20:17:47] - MMM-trakt - :  Trakt Access Code: 5C501BE1
[20:18:17] - MMM-trakt - :  Trakt Access Code: 4716B2D7
[20:18:47] - MMM-trakt - :  Trakt Access Code: 01098E31
[20:19:17] - MMM-trakt - :  Trakt Access Code: 37C26D20
[20:19:47] - MMM-trakt - :  Trakt Access Code: A971485F
[20:20:17] - MMM-trakt - :  Trakt Access Code: 63CC0216
[20:20:47] - MMM-trakt - :  Trakt Access Code: 126339B9
[20:21:17] - MMM-trakt - :  Trakt Access Code: 3E97A4E4
[20:21:17] - ERROR MMM-trakt :  Error: Expired
    at call (/MagicMirror/modules/MMM-trakt/node_modules/trakt.tv/trakt.js:319:35)
    at Timeout.setInterval (/MagicMirror/modules/MMM-trakt/node_modules/trakt.tv/trakt.js:343:17)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)  - [    at trakt.get_codes.then.catch.error (/MagicMirror/modules/MMM-trakt/node_helper.js:42:34)]
[20:21:17] - MMM-trakt - :  { access_token: undefined,
  expires: undefined,
  refresh_token: undefined }
[20:21:17] - DEBUG - MMM-trakt - :  Trakt {
  _authentication: 
   { access_token: undefined,
     expires: undefined,
     refresh_token: undefined },
  _settings: 
   { client_id: '(DELETED)',
     client_secret: '(DELETED)',
     redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
     debug: undefined,
     endpoint: 'https://api.trakt.tv',
     pagination: undefined,
     useragent: 'trakt.tv/7.1.0 (NodeJS; +git+https://github.com/vankasteelj/trakt.tv.git)' },
  calendars: 
   { my: 
      { shows: [Function],
        new_shows: [Function],
        premieres_shows: [Function],
        movies: [Function],
        dvd: [Function] },
     all: 
      { shows: [Function],
        new_shows: [Function],
        premieres_shows: [Function],
        movies: [Function],
        dvd: [Function] } },
  checkin: { add: [Function], delete: [Function] },
  certifications: [Function],
  comments: 
   { comment: 
      { add: [Function],
        get: [Function],
        update: [Function],
        remove: [Function] },
     replies: { get: [Function], add: [Function] },
     item: [Function],
     likes: [Function],
     like: { add: [Function], remove: [Function] },
     trending: [Function],
     recent: [Function],
     updates: [Function] },
  lists: { trending: [Function], popular: [Function] },
  genres: [Function],
  movies: 
   { trending: [Function],
     popular: [Function],
     played: [Function],
     watched: [Function],
     collected: [Function],
     anticipated: [Function],
     boxoffice: [Function],
     updates: [Function],
     summary: [Function],
     aliases: [Function],
     releases: [Function],
     translations: [Function],
     comments: [Function],
     lists: [Function],
     people: [Function],
     ratings: [Function],
     related: [Function],
     stats: [Function],
     watching: [Function] },
  networks: [Function],
  people: 
   { summary: [Function],
     movies: [Function],
     shows: [Function],
     lists: [Function] },
  recommendations: 
   { movies: { get: [Function], hide: [Function] },
     shows: { get: [Function], hide: [Function] } },
  scrobble: { start: [Function], pause: [Function], stop: [Function] },
  search: { text: [Function], id: [Function] },
  shows: 
   { trending: [Function],
     popular: [Function],
     played: [Function],
     watched: [Function],
     collected: [Function],
     anticipated: [Function],
     updates: [Function],
     summary: [Function],
     aliases: [Function],
     translations: [Function],
     comments: [Function],
     lists: [Function],
     progress: { collection: [Function], watched: [Function] },
     people: [Function],
     ratings: [Function],
     related: [Function],
     stats: [Function],
     watching: [Function],
     next_episode: [Function],
     last_episode: [Function] },
  seasons: 
   { summary: [Function],
     season: [Function],
     comments: [Function],
     lists: [Function],
     ratings: [Function],
     watching: [Function] },
  episodes: 
   { summary: [Function],
     translations: [Function],
     comments: [Function],
     lists: [Function],
     ratings: [Function],
     stats: [Function],
     watching: [Function] },
  sync: 
   { last_activities: [Function],
     playback: { get: [Function], remove: [Function] },
     collection: { get: [Function], add: [Function], remove: [Function] },
     watched: [Function],
     history: { get: [Function], add: [Function], remove: [Function] },
     ratings: { get: [Function], add: [Function], remove: [Function] },
     watchlist: { get: [Function], add: [Function], remove: [Function] } },
  users: 
   { settings: [Function],
     requests: { get: [Function], approve: [Function], deny: [Function] },
     hidden: { get: [Function], add: [Function], remove: [Function] },
     likes: [Function],
     profile: [Function],
     collection: [Function],
     comments: [Function],
     lists: { get: [Function], create: [Function], reorder: [Function] },
     list: 
      { get: [Function],
        update: [Function],
        delete: [Function],
        like: [Object],
        items: [Object],
        comments: [Function] },
     follow: { add: [Function], remove: [Function] },
     followers: [Function],
     following: [Function],
     friends: [Function],
     history: [Function],
     ratings: [Function],
     watchlist: [Function],
     watching: [Function],
     watched: [Function],
     stats: [Function] } }
(node:10458) UnhandledPromiseRejectionWarning: Error: OAuth required
    at Trakt._call (/MagicMirror/modules/MMM-trakt/node_modules/trakt.tv/trakt.js:195:122)
    at Object.tmp.(anonymous function) [as shows] (/MagicMirror/modules/MMM-trakt/node_modules/trakt.tv/trakt.js:49:33)
    at trakt.import_token.then.newTokens (/MagicMirror/modules/MMM-trakt/node_helper.js:55:32)
    at <anonymous>
(node:10458) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 22)
(node:10458) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Kiina commented 5 years ago

Oh yeah, instead of just logging the error and continuing we should probably return Promise.reject(error); and restart the get_codes promise. Never actually tried to idle for so long, so I never saw this error.