From 8f6be7c11aa0f005fdc341985635cea3a4f815bb Mon Sep 17 00:00:00 2001 From: Alec Watson Date: Sat, 28 Sep 2024 18:25:13 +0200 Subject: [PATCH 1/2] Fix for lounge middleware and production changes --- .github/workflows/deploy.yml | 4 - CoVAR-app/src/app/(pages)/lounge/page.tsx | 100 +++++++++++----------- docker-compose.prod.yml | 22 +---- langchain/__pycache__/app.cpython-39.pyc | Bin 1407 -> 7217 bytes langchain/requirements.txt | 3 +- 5 files changed, 54 insertions(+), 75 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1e921cc..1aad67e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -77,8 +77,6 @@ jobs: - name: Create Pem Files run: | - echo ${{ secrets.PUBLIC }} > langchain/public.pem - echo ${{ secrets.PRIVATE }} > langchain/private.pem echo ${{ secrets.PUBLIC }} > server/public.pem echo ${{ secrets.PRIVATE }} > server/private.pem echo ${{ secrets.REFRESH_PUBLIC }} > server/refreshPublic.pem @@ -90,11 +88,9 @@ jobs: docker build -t 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_api:latest ./server docker build -t 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_client:latest ./CoVAR-app docker build -t 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_nginx:latest ./nginx - docker build -t 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_langchain:latest ./langchain docker push 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_api:latest docker push 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_client:latest docker push 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_nginx:latest - docker push 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_langchain:latest deploy-containers: runs-on: ubuntu-latest diff --git a/CoVAR-app/src/app/(pages)/lounge/page.tsx b/CoVAR-app/src/app/(pages)/lounge/page.tsx index b8a5b03..ed66803 100644 --- a/CoVAR-app/src/app/(pages)/lounge/page.tsx +++ b/CoVAR-app/src/app/(pages)/lounge/page.tsx @@ -8,12 +8,17 @@ import { useRouter } from 'next/navigation'; import { doSignOut } from '../../../functions/firebase/auth'; import axios from 'axios'; - - const Lounge: React.FC = () => { const router = useRouter(); const pollingRef = useRef(null); + // Clear the cookie on component mount + useEffect(() => { + console.log("chicken"); + // Clear the accessToken cookie + document.cookie = 'accessToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + }, []); + const handleSignOut = async () => { try { await doSignOut(); @@ -23,59 +28,56 @@ const Lounge: React.FC = () => { } }; -// Function to get the current user and check their role -const checkUserStatus = useCallback(async () => { - try { - const response = await axios.post( - '/api/getUser', - { accessToken: localStorage.getItem('accessToken') }, - { headers: { Authorization: `Bearer ${localStorage.getItem('accessToken')}` } } - ); - - const {role} = response.data; - console.log("Role:", role); - - if (role !== 'unauthorised') { - router.replace('/dashboard'); - } - - } catch (error) { - console.error('Error fetching user status:', error); - } -}, [router]); - -// Start polling every 5 seconds -const startPolling = useCallback(() => { - if (!pollingRef.current) { - pollingRef.current = setInterval(() => { - checkUserStatus(); - }, 5000); - } -}, [checkUserStatus]); + // Function to get the current user and check their role + const checkUserStatus = useCallback(async () => { + try { + const response = await axios.post( + '/api/getUser', + { accessToken: localStorage.getItem('accessToken') }, + { headers: { Authorization: `Bearer ${localStorage.getItem('accessToken')}` } } + ); + const { role } = response.data; + console.log("Role:", role); + if (role !== 'unauthorised') { + router.replace('/dashboard'); + } -const stopPolling = useCallback(() => { - if (pollingRef.current) { - clearInterval(pollingRef.current); - pollingRef.current = null; - } -}, []); + } catch (error) { + console.error('Error fetching user status:', error); + } + }, [router]); + + // Start polling every 5 seconds + const startPolling = useCallback(() => { + if (!pollingRef.current) { + pollingRef.current = setInterval(() => { + checkUserStatus(); + }, 5000); + } + }, [checkUserStatus]); + const stopPolling = useCallback(() => { + if (pollingRef.current) { + clearInterval(pollingRef.current); + pollingRef.current = null; + } + }, []); -useEffect(() => { - startPolling(); + useEffect(() => { + startPolling(); - return () => { - stopPolling(); - }; -}, [startPolling, stopPolling]); + return () => { + stopPolling(); + }; + }, [startPolling, stopPolling]); return ( -

+
CoVAR @@ -86,14 +88,14 @@ useEffect(() => { Please wait here until an administrator verifies your account. -

-

+
+
-

-

-

+
+
+