@@ -143,7 +143,13 @@ export default class InternalClient {
143143
144144 if ( this . client . options . revive && ! forced ) {
145145 this . setup ( ) ;
146- this . login ( this . email , this . password ) ;
146+
147+ // Check whether the email is set (if not, only a token has been used for login)
148+ if ( this . email ) {
149+ this . login ( this . email , this . password ) ;
150+ } else {
151+ this . loginWithToken ( this . token ) ;
152+ }
147153 }
148154
149155 this . client . emit ( "disconnected" ) ;
@@ -296,6 +302,21 @@ export default class InternalClient {
296302 } ) ;
297303 }
298304
305+ // def loginWithToken
306+ // email and password are optional
307+ loginWithToken ( token , email , password ) {
308+ this . state = ConnectionState . LOGGED_IN ;
309+ this . token = token ;
310+ this . email = email ;
311+ this . password = password ;
312+
313+ return this . getGateway ( )
314+ . then ( url => {
315+ this . createWS ( url ) ;
316+ return token ;
317+ } ) ;
318+ }
319+
299320 // def login
300321 login ( email , password ) {
301322 var client = this . client ;
@@ -310,18 +331,7 @@ export default class InternalClient {
310331 var tk = this . tokenCacher . getToken ( email , password ) ;
311332 if ( tk ) {
312333 this . client . emit ( "debug" , "bypassed direct API login, used cached token" ) ;
313- this . state = ConnectionState . LOGGED_IN ;
314- this . token = tk ;
315- this . email = email ;
316- this . password = password ;
317-
318- return this . getGateway ( )
319- . then ( url => {
320- this . createWS ( url ) ;
321- return tk ;
322- } ) ;
323-
324- return Promise . resolve ( tk ) ;
334+ return loginWithToken ( tk , email , password ) ;
325335 }
326336 }
327337
@@ -339,16 +349,7 @@ export default class InternalClient {
339349 this . client . emit ( "debug" , "direct API login, cached token was unavailable" ) ;
340350 var token = res . token ;
341351 this . tokenCacher . setToken ( email , password , token ) ;
342- this . state = ConnectionState . LOGGED_IN ;
343- this . token = token ;
344- this . email = email ;
345- this . password = password ;
346-
347- return this . getGateway ( )
348- . then ( url => {
349- this . createWS ( url ) ;
350- return token ;
351- } ) ;
352+ loginWithToken ( token , email , password ) ;
352353 } , error => {
353354 this . websocket = null ;
354355 throw error ;
@@ -955,6 +956,9 @@ export default class InternalClient {
955956
956957 //def updateDetails
957958 updateDetails ( data ) {
959+ if ( ! email ) {
960+ throw new Error ( "Can't use updateDetails because only a token has been used for login!" ) ;
961+ }
958962 return this . apiRequest ( "patch" , Endpoints . ME , true , {
959963 avatar : this . resolver . resolveToBase64 ( data . avatar ) || this . user . avatar ,
960964 email : data . email || this . email ,
0 commit comments