@@ -178,18 +178,20 @@ export class Bluelink {
178178 this . logger = getBluelinkLogger ( )
179179 }
180180
181- protected async superInit ( config : Config , statusCheckInterval ?: number ) {
181+ protected async superInit ( config : Config , refreshAuth : boolean , statusCheckInterval ?: number ) {
182182 this . vin = this . config . vin
183183 this . statusCheckInterval = statusCheckInterval || DEFAULT_STATUS_CHECK_INTERVAL
184184
185+ // check for cache - if not this is first login
186+ const existingCache = this . cacheExists ( )
185187 // loadCache will login user if the cache doesnt exist i.e first app use
186188 const cache = await this . loadCache ( )
187189 if ( ! cache ) {
188190 this . loginFailure = true
189191 return
190192 }
191193 this . cache = cache
192- await this . refreshLogin ( )
194+ if ( existingCache && refreshAuth ) await this . refreshLogin ( )
193195 }
194196
195197 protected async refreshLogin ( force ?: boolean ) {
@@ -322,6 +324,10 @@ export class Bluelink {
322324 }
323325 }
324326
327+ public async refreshAuth ( force = false ) : Promise < void > {
328+ return await this . refreshLogin ( force )
329+ }
330+
325331 public async getStatus ( forceUpdate : boolean , noCache : boolean , location : boolean = false ) : Promise < Status > {
326332 if ( forceUpdate ) {
327333 // getCar first then save then get remote status
@@ -439,6 +445,10 @@ export class Bluelink {
439445 Keychain . set ( this . getCacheKey ( true ) , JSON . stringify ( this . cache ) )
440446 }
441447
448+ protected cacheExists ( ) : boolean {
449+ return Keychain . contains ( this . getCacheKey ( ) )
450+ }
451+
442452 protected async loadCache ( ) : Promise < Cache | undefined > {
443453 let cache : Cache | undefined = undefined
444454 if ( Keychain . contains ( this . getCacheKey ( ) ) ) {
0 commit comments