Merge pull request #142 from getmaxun/google-oauth-redirect

fix: google oauth redirect
This commit is contained in:
Karishma Shukla
2024-11-09 22:38:31 +05:30
committed by GitHub
4 changed files with 119 additions and 94 deletions

View File

@@ -32,9 +32,10 @@ services:
environment: environment:
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY} MINIO_ROOT_USER: ${MINIO_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY} MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY}
command: server /data command: server /data --console-address :9001
ports: ports:
- "9000:9000" - "9000:9000" # API port
- "9001:9001" # WebUI port
volumes: volumes:
- minio_data:/data - minio_data:/data

View File

@@ -341,12 +341,14 @@ router.get('/google/callback', requireSignIn, async (req: AuthenticatedRequest,
const jwtToken = jwt.sign({ userId: user.id }, process.env.JWT_SECRET as string, { expiresIn: '12h' }); const jwtToken = jwt.sign({ userId: user.id }, process.env.JWT_SECRET as string, { expiresIn: '12h' });
res.cookie('token', jwtToken, { httpOnly: true }); res.cookie('token', jwtToken, { httpOnly: true });
res.json({ // res.json({
message: 'Google authentication successful', // message: 'Google authentication successful',
google_sheet_email: robot.google_sheet_email, // google_sheet_email: robot.google_sheet_email,
jwtToken, // jwtToken,
files // files
}); // });
res.redirect(`http://localhost:5173`);
} catch (error: any) { } catch (error: any) {
res.status(500).json({ message: `Google OAuth error: ${error.message}` }); res.status(500).json({ message: `Google OAuth error: ${error.message}` });
} }

View File

@@ -21,38 +21,39 @@ minioClient.bucketExists('maxun-test')
console.error('Error connecting to MinIO:', err); console.error('Error connecting to MinIO:', err);
}) })
async function createBucketWithPolicy(bucketName: string, policy?: 'public-read' | 'private') { async function createBucketWithPolicy(bucketName: string, policy = 'public-read') {
try { try {
const bucketExists = await minioClient.bucketExists(bucketName); const bucketExists = await minioClient.bucketExists(bucketName);
if (!bucketExists) { if (!bucketExists) {
await minioClient.makeBucket(bucketName); await minioClient.makeBucket(bucketName);
console.log(`Bucket ${bucketName} created successfully.`); console.log(`Bucket ${bucketName} created successfully.`);
if (policy === 'public-read') {
// Define a public-read policy
const policyJSON = {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: "",
Action: ["s3:GetObject"],
Resource: [`arn:aws:s3:::${bucketName}/*`]
}
]
};
await minioClient.setBucketPolicy(bucketName, JSON.stringify(policyJSON));
console.log(`Public-read policy applied to bucket ${bucketName}.`);
}
} else { } else {
console.log(`Bucket ${bucketName} already exists.`); console.log(`Bucket ${bucketName} already exists.`);
} }
if (policy === 'public-read') {
// Apply public-read policy after confirming the bucket exists
const policyJSON = {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: "*",
Action: ["s3:GetObject"],
Resource: [`arn:aws:s3:::${bucketName}/*`]
}
]
};
await minioClient.setBucketPolicy(bucketName, JSON.stringify(policyJSON));
console.log(`Public-read policy applied to bucket ${bucketName}.`);
}
} catch (error) { } catch (error) {
console.error('Error in bucket creation or policy application:', error); console.error('Error in bucket creation or policy application:', error);
} }
} }
class BinaryOutputService { class BinaryOutputService {
private bucketName: string; private bucketName: string;

View File

@@ -1,12 +1,16 @@
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from "react";
import styled from "styled-components"; import styled from "styled-components";
import BrowserNavBar from "../molecules/BrowserNavBar"; import BrowserNavBar from "../molecules/BrowserNavBar";
import { BrowserWindow } from "./BrowserWindow"; import { BrowserWindow } from "./BrowserWindow";
import { useBrowserDimensionsStore } from "../../context/browserDimensions"; import { useBrowserDimensionsStore } from "../../context/browserDimensions";
import { BrowserTabs } from "../molecules/BrowserTabs"; import { BrowserTabs } from "../molecules/BrowserTabs";
import { useSocketStore } from "../../context/socket"; import { useSocketStore } from "../../context/socket";
import { getCurrentTabs, getCurrentUrl, interpretCurrentRecording } from "../../api/recording"; import {
import { Box } from '@mui/material'; getCurrentTabs,
getCurrentUrl,
interpretCurrentRecording,
} from "../../api/recording";
import { Box } from "@mui/material";
import { InterpretationLog } from "../molecules/InterpretationLog"; import { InterpretationLog } from "../molecules/InterpretationLog";
// TODO: Tab !show currentUrl after recordingUrl global state // TODO: Tab !show currentUrl after recordingUrl global state
@@ -14,107 +18,125 @@ export const BrowserContent = () => {
const { width } = useBrowserDimensionsStore(); const { width } = useBrowserDimensionsStore();
const { socket } = useSocketStore(); const { socket } = useSocketStore();
const [tabs, setTabs] = useState<string[]>(['current']); const [tabs, setTabs] = useState<string[]>(["current"]);
const [tabIndex, setTabIndex] = React.useState(0); const [tabIndex, setTabIndex] = React.useState(0);
const [showOutputData, setShowOutputData] = useState(false); const [showOutputData, setShowOutputData] = useState(false);
const handleChangeIndex = useCallback((index: number) => { const handleChangeIndex = useCallback(
setTabIndex(index); (index: number) => {
}, [tabIndex]) setTabIndex(index);
},
[tabIndex]
);
const handleCloseTab = useCallback((index: number) => { const handleCloseTab = useCallback(
// the tab needs to be closed on the backend (index: number) => {
socket?.emit('closeTab', { // the tab needs to be closed on the backend
index, socket?.emit("closeTab", {
isCurrent: tabIndex === index, index,
}); isCurrent: tabIndex === index,
// change the current index as current tab gets closed });
if (tabIndex === index) { // change the current index as current tab gets closed
if (tabs.length > index + 1) { if (tabIndex === index) {
handleChangeIndex(index); if (tabs.length > index + 1) {
handleChangeIndex(index);
} else {
handleChangeIndex(index - 1);
}
} else { } else {
handleChangeIndex(index - 1); handleChangeIndex(tabIndex - 1);
} }
} else { // update client tabs
handleChangeIndex(tabIndex - 1); setTabs((prevState) => [
} ...prevState.slice(0, index),
// update client tabs ...prevState.slice(index + 1),
setTabs((prevState) => [ ]);
...prevState.slice(0, index), },
...prevState.slice(index + 1) [tabs, socket, tabIndex]
]) );
}, [tabs, socket, tabIndex]);
const handleAddNewTab = useCallback(() => { const handleAddNewTab = useCallback(() => {
// Adds new tab by pressing the plus button // Adds new tab by pressing the plus button
socket?.emit('addTab'); socket?.emit("addTab");
// Adds a new tab to the end of the tabs array and shifts focus // Adds a new tab to the end of the tabs array and shifts focus
setTabs((prevState) => [...prevState, 'new tab']); setTabs((prevState) => [...prevState, "new tab"]);
handleChangeIndex(tabs.length); handleChangeIndex(tabs.length);
}, [socket, tabs]); }, [socket, tabs]);
const handleNewTab = useCallback((tab: string) => { const handleNewTab = useCallback(
// Adds a new tab to the end of the tabs array and shifts focus (tab: string) => {
setTabs((prevState) => [...prevState, tab]); // Adds a new tab to the end of the tabs array and shifts focus
// changes focus on the new tab - same happens in the remote browser setTabs((prevState) => [...prevState, tab]);
handleChangeIndex(tabs.length); // changes focus on the new tab - same happens in the remote browser
handleTabChange(tabs.length); handleChangeIndex(tabs.length);
}, [tabs]); handleTabChange(tabs.length);
},
[tabs]
);
const handleTabChange = useCallback((index: number) => { const handleTabChange = useCallback(
// page screencast and focus needs to be changed on backend (index: number) => {
socket?.emit('changeTab', index); // page screencast and focus needs to be changed on backend
}, [socket]); socket?.emit("changeTab", index);
},
[socket]
);
const handleUrlChanged = (url: string) => { const handleUrlChanged = (url: string) => {
const parsedUrl = new URL(url); const parsedUrl = new URL(url);
if (parsedUrl.hostname) { if (parsedUrl.hostname) {
const host = parsedUrl.hostname.match(/\b(?!www\.)[a-zA-Z0-9]+/g)?.join('.') const host = parsedUrl.hostname
.match(/\b(?!www\.)[a-zA-Z0-9]+/g)
?.join(".");
if (host && host !== tabs[tabIndex]) { if (host && host !== tabs[tabIndex]) {
setTabs((prevState) => [ setTabs((prevState) => [
...prevState.slice(0, tabIndex), ...prevState.slice(0, tabIndex),
host, host,
...prevState.slice(tabIndex + 1) ...prevState.slice(tabIndex + 1),
]) ]);
} }
} else { } else {
if (tabs[tabIndex] !== 'new tab') { if (tabs[tabIndex] !== "new tab") {
setTabs((prevState) => [ setTabs((prevState) => [
...prevState.slice(0, tabIndex), ...prevState.slice(0, tabIndex),
'new tab', "new tab",
...prevState.slice(tabIndex + 1) ...prevState.slice(tabIndex + 1),
]) ]);
} }
} }
}; };
const tabHasBeenClosedHandler = useCallback((index: number) => { const tabHasBeenClosedHandler = useCallback(
handleCloseTab(index); (index: number) => {
}, [handleCloseTab]) handleCloseTab(index);
},
[handleCloseTab]
);
useEffect(() => { useEffect(() => {
if (socket) { if (socket) {
socket.on('newTab', handleNewTab); socket.on("newTab", handleNewTab);
socket.on('tabHasBeenClosed', tabHasBeenClosedHandler); socket.on("tabHasBeenClosed", tabHasBeenClosedHandler);
} }
return () => { return () => {
if (socket) { if (socket) {
socket.off('newTab', handleNewTab); socket.off("newTab", handleNewTab);
socket.off('tabHasBeenClosed', tabHasBeenClosedHandler); socket.off("tabHasBeenClosed", tabHasBeenClosedHandler);
} }
} };
}, [socket, handleNewTab]) }, [socket, handleNewTab]);
useEffect(() => { useEffect(() => {
getCurrentTabs().then((response) => { getCurrentTabs()
if (response) { .then((response) => {
setTabs(response); if (response) {
} setTabs(response);
}).catch((error) => { }
console.log("Fetching current url failed"); })
}) .catch((error) => {
}, []) console.log("Fetching current url failed");
});
}, [handleUrlChanged]);
return ( return (
<div id="browser"> <div id="browser">
@@ -134,7 +156,6 @@ export const BrowserContent = () => {
<BrowserWindow /> <BrowserWindow />
</div> </div>
); );
} };
const BrowserContentWrapper = styled.div` const BrowserContentWrapper = styled.div``;
`;