From 39f854395d19297e0eb269278ca6149d03c371e7 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Fri, 18 Feb 2022 10:47:58 -0600 Subject: [PATCH 1/3] Fix bug with potential infinite recursion on 401 error --- src/client.ts | 8 +++++--- src/mysky/index.ts | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/client.ts b/src/client.ts index 1916a99c..ec7c0a1a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -85,7 +85,7 @@ export type CustomClientOptions = { customCookie?: string; onDownloadProgress?: (progress: number, event: ProgressEvent) => void; onUploadProgress?: (progress: number, event: ProgressEvent) => void; - loginFn?: () => Promise; + loginFn?: (config: RequestConfig) => Promise; }; /** @@ -374,8 +374,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 d03be7a7..65a0c57b 100644 --- a/src/mysky/index.ts +++ b/src/mysky/index.ts @@ -635,9 +635,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 @@ -651,7 +651,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 From f76d63cc1e644849d3df08cfb34b0c430ae09b32 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Fri, 25 Feb 2022 16:42:22 -0600 Subject: [PATCH 2/3] Fix skapp not clearing old portal login function --- src/mysky/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mysky/index.ts b/src/mysky/index.ts index 65a0c57b..86571b2f 100644 --- a/src/mysky/index.ts +++ b/src/mysky/index.ts @@ -616,6 +616,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; } } From eb691971da5d31ffce454e33ef5369808ec09501 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Tue, 8 Mar 2022 11:43:25 -0600 Subject: [PATCH 3/3] Prevent breaking change in `loginFn` --- src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index dce59b4b..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?: (config: RequestConfig) => Promise; + loginFn?: (config?: RequestConfig) => Promise; }; /**