From 46d17e0570eaae1aafc76829796fcbd602a5de0d Mon Sep 17 00:00:00 2001 From: arc-alex Date: Fri, 24 Nov 2023 21:17:30 +0100 Subject: [PATCH] extend authServer timeout if opened again --- .../modals/sheets-modal/SheetsModal.tsx | 19 ++++++++++++++++--- apps/server/src/utils/sheetsAuth.ts | 11 ++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx index ccd11cf7e..6a3309e03 100644 --- a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx +++ b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx @@ -10,6 +10,8 @@ import { ModalHeader, ModalOverlay, } from '@chakra-ui/react'; +import { IoArrowDownCircleOutline } from '@react-icons/all-files/io5/IoArrowDownCircleOutline'; +import { IoArrowUpCircleOutline } from '@react-icons/all-files/io5/IoArrowUpCircleOutline'; import { IoCheckmarkCircleOutline } from '@react-icons/all-files/io5/IoCheckmarkCircleOutline'; import { IoCloseCircleOutline } from '@react-icons/all-files/io5/IoCloseCircleOutline'; import { useQueryClient } from '@tanstack/react-query'; @@ -106,7 +108,8 @@ export default function SheetsModal(props: SheetsModalProps) { const handleAuthenticate = () => { getSheetsAuthUrl().then((data) => { if (data != 'bad') { - window.open(data, '_blank', 'noreferrer'); + const authWindow = window.open(data, '_blank', 'noreferrer'); + //TODO: can we detect when this window is closed } }); }; @@ -224,10 +227,20 @@ export default function SheetsModal(props: SheetsModalProps) { {!rundown && (
- -
diff --git a/apps/server/src/utils/sheetsAuth.ts b/apps/server/src/utils/sheetsAuth.ts index a17f3d6d4..88119a118 100644 --- a/apps/server/src/utils/sheetsAuth.ts +++ b/apps/server/src/utils/sheetsAuth.ts @@ -308,6 +308,7 @@ class sheet { }; } + private authServerTimeout; /** * create local Auth Server - returns url to serve on success * @returns {Promise} @@ -316,6 +317,14 @@ class sheet { public async openAuthServer(): Promise { //TODO: this only works on local networks if (sheet.authUrl) { + clearTimeout(this.authServerTimeout); + this.authServerTimeout = setTimeout( + () => { + sheet.authUrl = null; + server.unref; + }, + 2 * 60 * 1000, + ); return sheet.authUrl; } const creadFile = await readFile(this.client_secret, 'utf-8').catch((err) => @@ -396,7 +405,7 @@ class sheet { scope: this.scope, }); sheet.authUrl = authorizeUrl; - setTimeout( + this.authServerTimeout = setTimeout( () => { sheet.authUrl = null; server.unref;