diff --git a/src/client.ts b/src/client.ts index c84c4a85..84ec9e13 100644 --- a/src/client.ts +++ b/src/client.ts @@ -79,7 +79,7 @@ export type CustomClientOptions = { customCookie?: string; onDownloadProgress?: (progress: number, event: ProgressEvent) => void; onUploadProgress?: (progress: number, event: ProgressEvent) => void; - loginFn?: () => Promise; + loginFn?: (config?: RequestConfig) => Promise; }; /** @@ -359,8 +359,10 @@ export class SkynetClient { } catch (e) { if (config.loginFn && (e as ExecuteRequestError).responseStatus === 401) { // Try logging in again. - await config.loginFn(); - return await this.executeRequest(config); + await config.loginFn(config); + // Unset the login function on the recursive call so that we don't try + // to login again, avoiding infinite loops. + return await this.executeRequest({ ...config, loginFn: undefined }); } else { throw e; } diff --git a/src/mysky/index.ts b/src/mysky/index.ts index 24ae58cf..c6d78018 100644 --- a/src/mysky/index.ts +++ b/src/mysky/index.ts @@ -632,6 +632,9 @@ export class MySky { // // If we can log in to the portal account, set up auto-relogin. // if (await this.checkPortalLogin()) { // this.connector.client.customOptions.loginFn = this.portalLogin; + // } else { + // // Clear the old login function. + // this.connector.client.customOptions.loginFn = undefined; // } // } catch (e) { // // Don't throw an error if we couldn't redirect. The user will never be @@ -660,9 +663,9 @@ export class MySky { * Load MySky redirect flow: * * 1. SDK opens MySky on the same portal as the skapp. - * 2. If the preferred portal is found in localstorage, MySky connects to it - * and we go to step 5. - * 3. Else, MySky connects to siasky.net. + * 2. If a seed was not found, no preferred portal can be found, so exit the + * flow. + * 3. MySky connects to siasky.net first. * 4. MySky tries to get the saved portal preference. * 1. If the portal is set, MySky switches to using the preferred portal. * 2. If it is not set or we don't have the seed, MySky switches to using @@ -676,7 +679,7 @@ export class MySky { * Login redirect flow: * * 1. SDK logs in through the UI. - * 2. MySky UI switches to siasky.net and tries to get the saved portal + * 2. MySky switches to siasky.net and tries to get the saved portal * preference. * 1. If the portal is set, MySky switches to using the preferred portal. * 2. If it is not set or we don't have the seed, MySky switches to using