Skip to content

Commit

Permalink
Merge pull request #146 from COS301-SE-2024/fix/localstorageClear
Browse files Browse the repository at this point in the history
Fix for lounge middleware and production changes
  • Loading branch information
JBlixems authored Sep 29, 2024
2 parents 3ef41c7 + ff605e0 commit 01dc745
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 78 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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
Expand All @@ -91,11 +89,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
Expand Down
100 changes: 51 additions & 49 deletions CoVAR-app/src/app/(pages)/lounge/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeJS.Timeout | null>(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();
Expand All @@ -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 (
<Box sx={loungeContainerStyles}>
<Box sx={loungeBoxStyles}>
<Card sx={{ backgroundColor: 'background.paper', padding: 4, borderRadius: 2, borderStyle: 'solid', borderWidth: 1, borderColor: 'divider', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<br></br>
<br />
<LockOutlinedIcon sx={iconStyles} />
<Typography variant="h1" sx={brandTextStyles}>
CoVAR
Expand All @@ -86,14 +88,14 @@ useEffect(() => {
<Typography variant="body1" sx={loungeTextStyles}>
Please wait here until an administrator verifies your account.
</Typography>
<br></br>
<br></br>
<br />
<br />
<Box sx={{ display: 'flex', justifyContent: 'center', marginTop: 2 }}>
<CircularProgress color="primary" />
</Box>
<br></br>
<br></br>
<br></br>
<br />
<br />
<br />
<Button
variant="contained"
color="primary"
Expand Down
22 changes: 1 addition & 21 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
postgres:
image: 'postgres:latest'
image: 'postgres:16'
environment:
- POSTGRES_PASSWORD=${PG_PASSWORD}
- POSTGRES_USER=${PG_USER}
Expand Down Expand Up @@ -43,26 +43,6 @@ services:
- NEXT_PUBLIC_APP_ID=${NEXT_PUBLIC_APP_ID}
- NEXT_PUBLIC_MEASUREMENT_ID=${NEXT_PUBLIC_MEASUREMENT_ID}

langchain:
image: 211125691345.dkr.ecr.eu-west-2.amazonaws.com/covar_langchain:latest
environment:
- PG_USER=${PG_USER}
- PG_HOST=${PG_HOST}
- PG_DATABASE=${PG_DATABASE}
- PG_PASSWORD=${PG_PASSWORD}
- PG_PORT=${PG_PORT}
- FLASK_ENV=development
- MODEL_TYPE=${MODEL_TYPE}
- OPENAI_MODEL_NAME=${OPENAI_MODEL_NAME}
- API_KEY=${API_KEY}
ports:
- "6000:6000"
volumes:
- /app/node_modules
- ./langchain:/app
depends_on:
- postgres

volumes:
postgres_data:
driver: local
Binary file modified langchain/__pycache__/app.cpython-39.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion langchain/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ python-dotenv
openai
PyJWT
cryptography
gunicorn
gunicorn

6 changes: 3 additions & 3 deletions server/routes/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ router.post('/unmatchedRecommendations', authenticateToken, async (req, res) =>

try {
const token = req.headers.authorization;
const response = await axios.post('http://langchain:6000/unmatchedRecomendations',
const response = await axios.post('http://13.60.34.133/topVulChain',
{ chain_prompt_1 },
{ headers: { Authorization: token } }
);
Expand Down Expand Up @@ -79,7 +79,7 @@ router.post('/matchedRecommendations', authenticateToken, async (req, res) => {

try {
const token = req.headers.authorization;
const response = await axios.post('http://langchain:6000/matchedRecommendations',
const response = await axios.post('http://13.60.34.133/topVulChain',
{ chain_prompt_1, chain_prompt_2 },
{ headers: { Authorization: token } }
);
Expand Down Expand Up @@ -129,7 +129,7 @@ router.post('/topVulChain', authenticateToken, async (req, res) => {
try {
// Carry JWT through to chain server
const token = req.headers.authorization;
const response = await axios.post('http://langchain:6000/topVulChain', { chain_prompt }, { headers: { Authorization: token } });
const response = await axios.post('http://13.60.34.133/topVulChain', { chain_prompt }, { headers: { Authorization: token } });

res.status(200).json(response.data);
} catch (error) {
Expand Down

0 comments on commit 01dc745

Please sign in to comment.