aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-10-06 19:08:33 +0100
committerGravatar GitHub <[email protected]>2020-10-06 19:08:33 +0100
commit2b367c7aeea254655dd3011a4ed44b98f1caf0c9 (patch)
tree7b16343d9f95d329fdc025c75f15c30cecb71229 /src
parentMerge pull request #19 from python-discord/discord/add-oauth2-authorize (diff)
parentBetter handle other messages from the React DevTools extension (diff)
Merge pull request #20 from python-discord/discord/improve-oauth2-flow
Check for child window closure
Diffstat (limited to 'src')
-rw-r--r--src/components/OAuth2Button.tsx10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/components/OAuth2Button.tsx b/src/components/OAuth2Button.tsx
index 1b3d588..d67b1ab 100644
--- a/src/components/OAuth2Button.tsx
+++ b/src/components/OAuth2Button.tsx
@@ -50,8 +50,15 @@ function doLogin(disableFunction: (newState: boolean) => void) {
"height=700,width=500,location=no,menubar=no,resizable=no,status=no,titlebar=no,left=300,top=300"
)
+ const interval = setInterval(() => {
+ if (windowRef?.closed) {
+ clearInterval(interval);
+ disableFunction(false);
+ }
+ }, 500)
+
window.onmessage = (code: MessageEvent) => {
- if (code.data.hello) {
+ if (code.data.source) {
// React DevTools has a habit of sending messages, ignore them.
return;
}
@@ -62,6 +69,7 @@ function doLogin(disableFunction: (newState: boolean) => void) {
console.log("Code received:", code.data);
disableFunction(false);
+ clearInterval(interval);
window.onmessage = null;
}