-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hacking nango to catch user cancellation
- Loading branch information
Showing
5 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,8 @@ | |
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]" | ||
"[email protected]": "patches/[email protected]", | ||
"@nangohq/[email protected]": "patches/@[email protected]" | ||
}, | ||
"peerDependencyRules": { | ||
"allowedVersions": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
diff --git a/dist/index.d.ts b/dist/index.d.ts | ||
index 91d370b7ada12e8b27cc6706151d676b27a72c20..bee8cc225dc1e621bbab0902e0d7648cb81e1845 100644 | ||
--- a/dist/index.d.ts | ||
+++ b/dist/index.d.ts | ||
@@ -1,4 +1,5 @@ | ||
-type AuthError = { | ||
+/** Gets thrown by `create` and `auth` methods */ | ||
+export type AuthError = { | ||
message: string; | ||
type: string; | ||
}; | ||
@@ -14,14 +15,16 @@ export default class Nango { | ||
publicKey: string; | ||
debug?: boolean; | ||
}); | ||
+ /** @throws `AuthError` */ | ||
create(providerConfigKey: string, connectionId: string, connectionConfig: ConnectionConfig): Promise<{ | ||
providerConfigKey: string; | ||
connectionId: string; | ||
- } | AuthError>; | ||
+ }>; | ||
+ /** @throws `AuthError` */ | ||
auth(providerConfigKey: string, connectionId: string, conectionConfigOrCredentials?: ConnectionConfig | BasicApiCredentials | ApiKeyCredentials): Promise<{ | ||
providerConfigKey: string; | ||
connectionId: string; | ||
- } | AuthError>; | ||
+ }>; | ||
convertCredentialsToConfig(credentials: BasicApiCredentials | ApiKeyCredentials): ConnectionConfig; | ||
private apiAuth; | ||
private toQueryString; | ||
diff --git a/dist/index.js b/dist/index.js | ||
index 3ee0e9e9a72cb4d3fd611066811dd494b6839c7f..0014509fc6df476c7e662f4e7a44bd5dc355523e 100644 | ||
--- a/dist/index.js | ||
+++ b/dist/index.js | ||
@@ -217,6 +217,7 @@ class AuthorizationModal { | ||
this.swClient.onmessage = (message) => { | ||
this.handleMessage(message, successHandler, errorHandler); | ||
}; | ||
+ this.errorHandler = errorHandler; | ||
} | ||
/** | ||
* Handles the messages received from the Nango server via WebSocket. | ||
@@ -269,6 +270,19 @@ class AuthorizationModal { | ||
*/ | ||
open(wsClientId) { | ||
this.modal.location = this.url + '&ws_client_id=' + wsClientId; | ||
+ // @see https://github.com/NangoHQ/nango/pull/1073 for a real fix | ||
+ // Can remove this patch once it merges into master and gets released | ||
+ this.interval = setInterval(() => { | ||
+ if (this.modal?.closed) { | ||
+ setTimeout(() => { | ||
+ if (this.swClient.readyState !== this.swClient.CLOSED) { | ||
+ this.errorHandler('user_cancelled', 'User cancelled the authorization process.') | ||
+ this.swClient.close(); | ||
+ } | ||
+ clearInterval(this.interval) | ||
+ }, 500) | ||
+ } | ||
+ }, 500) | ||
return this.modal; | ||
} | ||
/** |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.