Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #403 from SkynetLabs/mysky-flow-updates
Browse files Browse the repository at this point in the history
Mysky flow updates
  • Loading branch information
mrcnski authored Mar 9, 2022
2 parents 4ac73d0 + eb69197 commit 2b0ebcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type CustomClientOptions = {
customCookie?: string;
onDownloadProgress?: (progress: number, event: ProgressEvent) => void;
onUploadProgress?: (progress: number, event: ProgressEvent) => void;
loginFn?: () => Promise<void>;
loginFn?: (config?: RequestConfig) => Promise<void>;
};

/**
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 7 additions & 4 deletions src/mysky/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,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
Expand Down Expand Up @@ -664,9 +667,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
Expand All @@ -680,7 +683,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
Expand Down

0 comments on commit 2b0ebcd

Please sign in to comment.