From 141de81c678ab279e2bec28d817e4d5a557b2565 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 01:56:52 +0530 Subject: [PATCH 01/34] feat(wip): api key ui --- src/components/organisms/ApiKey.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/components/organisms/ApiKey.tsx diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx new file mode 100644 index 00000000..c2708ba6 --- /dev/null +++ b/src/components/organisms/ApiKey.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +const ApiKey = () => { + return ( +
ApiKey
+ ) +} + +export default ApiKey \ No newline at end of file From b912ebfef97592677d95ef5231416ed40cbbcf9d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 01:57:53 +0530 Subject: [PATCH 02/34] chore: remove unused import --- src/pages/MainPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index a6a62258..21a81404 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useEffect } from 'react'; import { MainMenu } from "../components/organisms/MainMenu"; -import { Grid, Stack } from "@mui/material"; +import { Stack } from "@mui/material"; import { Recordings } from "../components/organisms/Recordings"; import { Runs } from "../components/organisms/Runs"; import ProxyForm from '../components/organisms/ProxyForm'; From e52d36c4f88ef362062b6e72bfb8c9a2a87a6b36 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:03:01 +0530 Subject: [PATCH 03/34] feat: apikey case --- src/pages/MainPage.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index 21a81404..e5d04b54 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -4,6 +4,7 @@ import { Stack } from "@mui/material"; import { Recordings } from "../components/organisms/Recordings"; import { Runs } from "../components/organisms/Runs"; import ProxyForm from '../components/organisms/ProxyForm'; +import ApiKey from '../components/organisms/ApiKey'; import { useGlobalInfoStore } from "../context/globalInfo"; import { createRunForStoredRecording, interpretStoredRecording, notifyAboutAbort, scheduleStoredRecording } from "../api/storage"; import { handleUploadCredentials } from "../api/integration" @@ -145,6 +146,8 @@ export const MainPage = ({ handleEditRecording }: MainPageProps) => { />; case 'proxy': return ; + case 'apikey': + return ; default: return null; } From 8e358409c8ce701d72c2c580e2f670d0e6716c27 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:03:45 +0530 Subject: [PATCH 04/34] feat: generate api key tab --- src/components/organisms/MainMenu.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index 50a9f849..f1b6c55a 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -47,6 +47,10 @@ export const MainMenu = ({ value = 'recordings', handleChangeContent }: MainMenu alignItems: 'baseline', fontSize: 'medium', }} value="proxy" label="Proxy" /> + From cb8ab85951264f15612e313f30251dc512d92938 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:03:57 +0530 Subject: [PATCH 05/34] chore: lint --- src/components/organisms/MainMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index f1b6c55a..eaa0e057 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -47,7 +47,7 @@ export const MainMenu = ({ value = 'recordings', handleChangeContent }: MainMenu alignItems: 'baseline', fontSize: 'medium', }} value="proxy" label="Proxy" /> - From 3ee30c0470dd673a509fdabcd7803184a3ae14e0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:09:03 +0530 Subject: [PATCH 06/34] chore: del api.ts --- server/src/routes/api.ts | 40 ------------------- .../routes/service_account_credentials.json | 1 - 2 files changed, 41 deletions(-) delete mode 100644 server/src/routes/api.ts delete mode 100644 server/src/routes/service_account_credentials.json diff --git a/server/src/routes/api.ts b/server/src/routes/api.ts deleted file mode 100644 index cc417bfb..00000000 --- a/server/src/routes/api.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Router, Request, Response } from 'express'; -import { genAPIKey } from '../utils/api'; -import User from '../models/User'; - -export const router = Router(); - -interface AuthenticatedRequest extends Request { - user?: { id: string }; -} - -router.get('/generate-api-key', async (req: AuthenticatedRequest, res) => { - try { - if (!req.user) { - return res.status(401).json({ ok: false, error: 'Unauthorized' }); - } - const user = await User.findByPk(req.user.id, { - attributes: { exclude: ['password'] }, - }); - - if (!user) { - return res.status(404).json({ message: 'User not found' }); - } - - if (user.api_key) { - return res.status(400).json({ message: 'API key already exists' }); - } - - const apiKey = genAPIKey(); - - user.api_key = apiKey; - await user.save(); - - return res.status(200).json({ - message: 'API key generated successfully', - api_key: apiKey, - }); - } catch (error) { - return res.status(500).json({ message: 'Error generating API key', error }); - } -}); diff --git a/server/src/routes/service_account_credentials.json b/server/src/routes/service_account_credentials.json deleted file mode 100644 index 602fcbe0..00000000 --- a/server/src/routes/service_account_credentials.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"service_account","project_id":"maxun12345","private_key_id":"45859ac1196ba6a371bf5427eb990e44b61d4237","private_key":"-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC0Sx73gWatvgGX\nhhtt/isiaH+EL1Y9K3X0404ZZndm7iNvILk190Jv2RjDNjASvWZBMcH72MKwaMkP\neYspK33DiA7+IDzE+tVefrC8PFPBepO3VtVfNeKe6xBMa3j2TwlfVgpDqPQBun69\nLuhvG1QMh1GfCnTi0wSeksRSiTS2KlmAuY79I/Y8KRQefLwoPZDDjVD9/3B0Xgly\nC3kKAtmfOSi+U1BUdVf3J58Tj57Yge2QpSBHBPjxwL60iadJoBSgcvBUXg+VgdXg\nqNyENYau5ohyvOjtW4Fhv/d7g/lyi84NBEn6+2ljFzY2xE0tZYM1CLouCU9MeDDu\ngvcHzGOnAgMBAAECggEAUwJbSZ18hvX6iacnLedeOMNgIp4g2J0P/CZDqRIyW2O9\nUMcCP0SOhCyyZ/6k95vYXp/oLmpIiSxVlhhh6BysFMCqFnsFP7Q1VQKDoMct0OD8\n7ea+6s1Gf+C+alD5Kn6NVCWrKCe74Kfa/oOAZNdyRSpwfAc2ddCuScxNM6sUZ+Ik\nK89fM576j8rfBAF1JW4ynQE/oM1y9A+88o1g602tOC5rm4vZH/Jv9tZwnfHMV+S7\n2PMSGDD1N4Mq1z3Gg3HjRHC/zo6SW6Jvk4O6mx9scIaui+u3nn7qQUVCLSMiFV3i\nsPv9zLktadu0h9o+6pCHSDuOFvFQOFIVEMU0fmgkQQKBgQD1Vnitk6X3aRBI/1u9\nJCk1l0GarfvdUed5fb3qRwH85vEhwmWKyglwDtWxxYNSNOIlpxOGKnq9CMdpkF15\nQO1bgbhsrbx75YYT29ulbAhLjm/tIP3OdvokzsH/Lz9qVh0AnEi+lgueRjerALvZ\nfZuLeSFi3FlxEX229a89TN9c0QKBgQC8IP4ea+Zu9hK+8qsF6htQEMqYagAMI63R\nwTVzRHL4H/GGYcs39ZjA9F0y0g65MAtT7+PfR8QifNUAJNRAnu5/CPDyQX9GvBM2\n9uBnwI1pJSdse1m0ez7kigl2TQDYaOADoSvRGALmBAFXXB7CNXgy8l1aQBiRvZjy\nulBQCcn29wKBgQDYQxM5ns9L2lc6oa6Sec/Bp8Vyvi8olsw+sfK5E0LTVhf0tFGi\nGBpdpxYEEKGD044NtstlFwj+nUB684ESI4OXiC+zzSo65MZdtw5VMXfWcoaDNvPE\nDejOjVtAwLtb1vDV2u3c4pL3P9pOaOUuAKUeOvaNGMPXAZ4Zq1R/6sVyIQKBgH93\nCzapfPPpnkHqQZ48RE03U015ZJbVBcx80C5NTmh3nDmkwQAlU15JM2xfjsJCnyo7\n+3UpNub3FYqHaZhvFsDT2g0J+6Z9f7daBinF+QootlF2Mg1rA+3s6QRSoCQAyucq\nqHl/f1dBl3cNX3nOqKY8OKwRiZQVli+/tPLF7yV5AoGBAI8+aLt3R9rioBtPFDUK\nuwxoeide0LH8UWFa5H+LV/13sWk6io/E6gdQOi1A2CrOdR+YFTCUG3VbIszbWCba\ne4Ws8Yy0CAvz0ePVE2aySJE0aRQWZH2BjPIckeGE8AGxViS1JiiX+wruYJiLSzx9\n+ejlxtjjkUsMoDd3trSI/s5d\n-----END PRIVATE KEY-----\n","client_email":"maxun-999@maxun12345.iam.gserviceaccount.com","client_id":"108198347095941384494","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/maxun-999%40maxun12345.iam.gserviceaccount.com","universe_domain":"googleapis.com"} \ No newline at end of file From 53b780901b17b9c8d3aacc4fd9cda7df0e7b7656 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:28:46 +0530 Subject: [PATCH 07/34] feat: get api key route --- server/src/routes/auth.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 3effb0d2..d3b243e6 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -121,3 +121,26 @@ router.post('/generate-api-key', requireSignIn, async (req: AuthenticatedRequest return res.status(500).json({ message: 'Error generating API key', error }); } }); + +router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => { + try { + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + attributes: ['api_key'], + }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + return res.status(200).json({ + message: 'API key fetched successfully', + api_key: user.api_key || null, + }); + } catch (error) { + return res.status(500).json({ message: 'Error fetching API key', error }); + } +}); \ No newline at end of file From 29d341f088094912c0db85716d688a3855f174c4 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:47:29 +0530 Subject: [PATCH 08/34] feat: generate api key --- src/components/organisms/ApiKey.tsx | 138 ++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 6 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index c2708ba6..5e33c67d 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -1,9 +1,135 @@ -import React from 'react' +import React, { useState, useEffect } from 'react'; +import { + Box, + Button, + TextField, + Typography, + IconButton, + InputAdornment, + Tooltip, + CircularProgress, +} from '@mui/material'; +import { Visibility, VisibilityOff, ContentCopy } from '@mui/icons-material'; +import styled from 'styled-components'; +import axios from 'axios'; +import { useGlobalInfoStore } from '../../context/globalInfo'; + +// Styled components +const Container = styled(Box)` + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; +`; + +const ApiKeyField = styled(TextField)` + width: 400px; + margin: 20px 0; +`; + +const HiddenText = styled(Typography)` + color: #888; + font-style: italic; +`; const ApiKey = () => { - return ( -
ApiKey
- ) -} + const [apiKey, setApiKey] = useState(null); + const [loading, setLoading] = useState(true); + const [showKey, setShowKey] = useState(false); + const [copySuccess, setCopySuccess] = useState(false); -export default ApiKey \ No newline at end of file + const {notify} = useGlobalInfoStore(); + + // Fetch API Key on mount + useEffect(() => { + const fetchApiKey = async () => { + try { + const { data } = await axios.get('http://localhost:8080/auth/api-key'); + setApiKey(data.api_key); + notify('info', `Fetc API Key: ${data.api_key}`); + } catch (error) { + console.error('Error fetching API key', error); + } finally { + setLoading(false); + } + }; + + fetchApiKey(); + }, []); + + // Handle API Key generation + const generateApiKey = async () => { + setLoading(true); + try { + const { data } = await axios.post('http://localhost:8080/auth/generate-api-key'); + setApiKey(data.api_key); + notify('info', `Genrate API Key: ${data.api_key}`); + } catch (error) { + console.error('Error generating API key', error); + } finally { + setLoading(false); + } + }; + + // Copy to clipboard handler + const copyToClipboard = () => { + if (apiKey) { + navigator.clipboard.writeText(apiKey); + setCopySuccess(true); + setTimeout(() => setCopySuccess(false), 2000); + } + }; + + // Toggle key visibility + const toggleShowKey = () => { + setShowKey(!showKey); + }; + + if (loading) return ; + + return ( + + Manage Your API Key + + {apiKey ? ( + <> + + + {showKey ? : } + + + ), + }} + /> + + + + {copySuccess && ( + + + + )} + + ) : ( + <> + You haven't generated an API key yet. + + + )} + + ); +}; + +export default ApiKey; From 0221c96cd8cb0cb407e0d74070b86692f6d44015 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:50:54 +0530 Subject: [PATCH 09/34] chore: -rm comments --- src/components/organisms/ApiKey.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 5e33c67d..7d38bb30 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -14,7 +14,6 @@ import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; -// Styled components const Container = styled(Box)` display: flex; flex-direction: column; @@ -40,7 +39,6 @@ const ApiKey = () => { const {notify} = useGlobalInfoStore(); - // Fetch API Key on mount useEffect(() => { const fetchApiKey = async () => { try { @@ -57,7 +55,6 @@ const ApiKey = () => { fetchApiKey(); }, []); - // Handle API Key generation const generateApiKey = async () => { setLoading(true); try { @@ -71,7 +68,6 @@ const ApiKey = () => { } }; - // Copy to clipboard handler const copyToClipboard = () => { if (apiKey) { navigator.clipboard.writeText(apiKey); @@ -80,7 +76,6 @@ const ApiKey = () => { } }; - // Toggle key visibility const toggleShowKey = () => { setShowKey(!showKey); }; From f0d35dbef802cf82ba085eaf0220a5f31a74deb8 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 02:51:08 +0530 Subject: [PATCH 10/34] chore: lint --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 7d38bb30..4e1f93d8 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -37,7 +37,7 @@ const ApiKey = () => { const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); - const {notify} = useGlobalInfoStore(); + const { notify } = useGlobalInfoStore(); useEffect(() => { const fetchApiKey = async () => { From 2210ab45a0bda9fb984f6b39d5a9a41f962993ef Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 03:04:17 +0530 Subject: [PATCH 11/34] feat: set raw: true --- server/src/routes/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index d3b243e6..7c74f6d2 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -17,7 +17,7 @@ router.post('/register', async (req, res) => { if (!email) return res.status(400).send('Email is required') if (!password || password.length < 6) return res.status(400).send('Password is required and must be at least 6 characters') - let userExist = await User.findOne({ where: { email } }); + let userExist = await User.findOne({ raw: true, where: { email } }); if (userExist) return res.status(400).send('User already exists') const hashedPassword = await hashPassword(password) From 40aea4c8a6969497f7296ab06e357ec547d0a697 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 03:28:49 +0530 Subject: [PATCH 12/34] feat: use update & set raw true --- server/src/routes/auth.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 7c74f6d2..d1d6a85d 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -107,11 +107,9 @@ router.post('/generate-api-key', requireSignIn, async (req: AuthenticatedRequest if (user.api_key) { return res.status(400).json({ message: 'API key already exists' }); } - const apiKey = genAPIKey(); - user.api_key = apiKey; - await user.save(); + await user.update({ api_key: apiKey }); return res.status(200).json({ message: 'API key generated successfully', @@ -129,6 +127,7 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => } const user = await User.findByPk(req.user.id, { + raw: true, attributes: ['api_key'], }); From dfd7097c779195c1fdd9b1ff6f1c5038f74d7f72 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 03:29:38 +0530 Subject: [PATCH 13/34] feat: better ui --- src/components/organisms/ApiKey.tsx | 33 +++++++++-------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 4e1f93d8..37401954 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -9,7 +9,7 @@ import { Tooltip, CircularProgress, } from '@mui/material'; -import { Visibility, VisibilityOff, ContentCopy } from '@mui/icons-material'; +import { ContentCopy } from '@mui/icons-material'; import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -31,10 +31,9 @@ const HiddenText = styled(Typography)` font-style: italic; `; -const ApiKey = () => { +const ApiKeyManager = () => { const [apiKey, setApiKey] = useState(null); const [loading, setLoading] = useState(true); - const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); const { notify } = useGlobalInfoStore(); @@ -44,7 +43,6 @@ const ApiKey = () => { try { const { data } = await axios.get('http://localhost:8080/auth/api-key'); setApiKey(data.api_key); - notify('info', `Fetc API Key: ${data.api_key}`); } catch (error) { console.error('Error fetching API key', error); } finally { @@ -60,7 +58,7 @@ const ApiKey = () => { try { const { data } = await axios.post('http://localhost:8080/auth/generate-api-key'); setApiKey(data.api_key); - notify('info', `Genrate API Key: ${data.api_key}`); + notify('info', `Generated API Key: ${data.api_key}`); } catch (error) { console.error('Error generating API key', error); } finally { @@ -76,10 +74,6 @@ const ApiKey = () => { } }; - const toggleShowKey = () => { - setShowKey(!showKey); - }; - if (loading) return ; return ( @@ -91,29 +85,22 @@ const ApiKey = () => { - - {showKey ? : } + + ), }} /> - - - {copySuccess && ( - - - - )} + {copySuccess && + Copied to Clipboard + } ) : ( <> @@ -127,4 +114,4 @@ const ApiKey = () => { ); }; -export default ApiKey; +export default ApiKeyManager; From af1a07bf14bdd778cd1756c7c3b526fd638a5caa Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 03:59:02 +0530 Subject: [PATCH 14/34] feat: set api key name --- server/src/models/User.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 9bc6affb..83156fd2 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -5,6 +5,7 @@ interface UserAttributes { id: number; email: string; password: string; + api_key_name?: string | null; api_key?: string | null; proxy_url?: string | null; proxy_username?: string | null; @@ -18,6 +19,7 @@ class User extends Model implements User public id!: number; public email!: string; public password!: string; + public api_key_name!: string | null; public api_key!: string | null; public proxy_url!: string | null; public proxy_username!: string | null; @@ -43,6 +45,11 @@ User.init( type: DataTypes.STRING, allowNull: false, }, + api_key_name: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: 'Maxun API Key', + }, api_key: { type: DataTypes.STRING, allowNull: true, From 9a6da85e73c7e9ec72fce826c0f3969c55b9a64b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:04:03 +0530 Subject: [PATCH 15/34] feat: set raw true --- server/src/routes/auth.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index d1d6a85d..9be81e69 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -97,6 +97,7 @@ router.post('/generate-api-key', requireSignIn, async (req: AuthenticatedRequest return res.status(401).json({ ok: false, error: 'Unauthorized' }); } const user = await User.findByPk(req.user.id, { + raw: true, attributes: { exclude: ['password'] }, }); From cb64235e497d0514c2ed233e4bc30dedeecb34f2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:05:15 +0530 Subject: [PATCH 16/34] feat: delete api key --- server/src/routes/auth.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 9be81e69..17a93196 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -143,4 +143,27 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => } catch (error) { return res.status(500).json({ message: 'Error fetching API key', error }); } -}); \ No newline at end of file +}); + +router.delete('/delete-api-key', requireSignIn, async (req: AuthenticatedRequest, res) => { + try { + if (!req.user) { + return res.status(401).json({ message: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + raw: true, + }); + + if (!user || !user.api_key) { + return res.status(404).json({ message: 'API Key not found' }); + } + + await user.update({ api_key: null }); + + return res.status(200).json({ message: 'API Key deleted successfully' }); + } catch (error) { + return res.status(500).json({ message: 'Error deleting API key', error }); + } + }); + \ No newline at end of file From 7c72c95e9b6ba3d4003819e3d684545e76da3e6b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:05:30 +0530 Subject: [PATCH 17/34] chore: lint --- server/src/routes/auth.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 17a93196..f3877f70 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -147,23 +147,22 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => router.delete('/delete-api-key', requireSignIn, async (req: AuthenticatedRequest, res) => { try { - if (!req.user) { - return res.status(401).json({ message: 'Unauthorized' }); - } - - const user = await User.findByPk(req.user.id, { - raw: true, - }); - - if (!user || !user.api_key) { - return res.status(404).json({ message: 'API Key not found' }); - } - - await user.update({ api_key: null }); - - return res.status(200).json({ message: 'API Key deleted successfully' }); + if (!req.user) { + return res.status(401).json({ message: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + raw: true, + }); + + if (!user || !user.api_key) { + return res.status(404).json({ message: 'API Key not found' }); + } + + await user.update({ api_key: null }); + + return res.status(200).json({ message: 'API Key deleted successfully' }); } catch (error) { - return res.status(500).json({ message: 'Error deleting API key', error }); + return res.status(500).json({ message: 'Error deleting API key', error }); } - }); - \ No newline at end of file +}); From e56511202774260c3b0f154a5d4ff766eaa172c4 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:15:57 +0530 Subject: [PATCH 18/34] feat: api key actions --- src/components/organisms/ApiKey.tsx | 100 ++++++++++++++++++---------- 1 file changed, 63 insertions(+), 37 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 37401954..d999ce76 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -2,14 +2,18 @@ import React, { useState, useEffect } from 'react'; import { Box, Button, - TextField, Typography, IconButton, - InputAdornment, - Tooltip, CircularProgress, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Tooltip, } from '@mui/material'; -import { ContentCopy } from '@mui/icons-material'; +import { ContentCopy, Visibility, Delete } from '@mui/icons-material'; import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -21,21 +25,12 @@ const Container = styled(Box)` margin-top: 50px; `; -const ApiKeyField = styled(TextField)` - width: 400px; - margin: 20px 0; -`; - -const HiddenText = styled(Typography)` - color: #888; - font-style: italic; -`; - const ApiKeyManager = () => { const [apiKey, setApiKey] = useState(null); + const [apiKeyName, setApiKeyName] = useState('Maxun API Key'); const [loading, setLoading] = useState(true); + const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); - const { notify } = useGlobalInfoStore(); useEffect(() => { @@ -66,6 +61,19 @@ const ApiKeyManager = () => { } }; + const deleteApiKey = async () => { + setLoading(true); + try { + await axios.delete('http://localhost:8080/auth/delete-api-key'); + setApiKey(null); + notify('success', 'API Key deleted successfully'); + } catch (error) { + console.error('Error deleting API key', error); + } finally { + setLoading(false); + } + }; + const copyToClipboard = () => { if (apiKey) { navigator.clipboard.writeText(apiKey); @@ -81,30 +89,48 @@ const ApiKeyManager = () => { Manage Your API Key {apiKey ? ( - <> - - - - - - ), - }} - /> - - {copySuccess && - Copied to Clipboard - } - + + + + + API Key Name + API Key + Actions + + + + + {apiKeyName} + {showKey ? apiKey : '****************'} + + + + + + + + setShowKey(!showKey)}> + + + + + + + + + + + +
+ {copySuccess && ( + + Copied to Clipboard + + )} +
) : ( <> - You haven't generated an API key yet. + You haven't generated an API key yet. From d8348386f3c9b050577bc6c52d27caa7a90e2a74 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:42:08 +0530 Subject: [PATCH 19/34] feat: del api key w rawtrye --- server/src/routes/auth.ts | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index f3877f70..230e2a5f 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -97,7 +97,6 @@ router.post('/generate-api-key', requireSignIn, async (req: AuthenticatedRequest return res.status(401).json({ ok: false, error: 'Unauthorized' }); } const user = await User.findByPk(req.user.id, { - raw: true, attributes: { exclude: ['password'] }, }); @@ -145,24 +144,23 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => } }); -router.delete('/delete-api-key', requireSignIn, async (req: AuthenticatedRequest, res) => { +router.delete('/delete-api-key', requireSignIn, async (req, res) => { try { - if (!req.user) { - return res.status(401).json({ message: 'Unauthorized' }); - } - - const user = await User.findByPk(req.user.id, { - raw: true, - }); - - if (!user || !user.api_key) { - return res.status(404).json({ message: 'API Key not found' }); - } - - await user.update({ api_key: null }); - - return res.status(200).json({ message: 'API Key deleted successfully' }); - } catch (error) { - return res.status(500).json({ message: 'Error deleting API key', error }); + const user = await User.findByPk(req.user.id, { raw: true }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + if (!user.api_key) { + return res.status(404).json({ message: 'API Key not found' }); + } + + await User.update({ api_key: null }, { where: { id: req.user.id } }); + + return res.status(200).json({ message: 'API Key deleted successfully' }); + } catch (error: any) { + return res.status(500).json({ message: 'Error deleting API key', error: error.message }); } -}); + }); + \ No newline at end of file From ec8e152b438554287ae08f30baa35fa5618c80e5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:42:24 +0530 Subject: [PATCH 20/34] chore: lint --- server/src/routes/auth.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 230e2a5f..c33409c2 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -146,21 +146,20 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => router.delete('/delete-api-key', requireSignIn, async (req, res) => { try { - const user = await User.findByPk(req.user.id, { raw: true }); - - if (!user) { - return res.status(404).json({ message: 'User not found' }); - } - - if (!user.api_key) { - return res.status(404).json({ message: 'API Key not found' }); - } - - await User.update({ api_key: null }, { where: { id: req.user.id } }); - - return res.status(200).json({ message: 'API Key deleted successfully' }); + const user = await User.findByPk(req.user.id, { raw: true }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + if (!user.api_key) { + return res.status(404).json({ message: 'API Key not found' }); + } + + await User.update({ api_key: null }, { where: { id: req.user.id } }); + + return res.status(200).json({ message: 'API Key deleted successfully' }); } catch (error: any) { - return res.status(500).json({ message: 'Error deleting API key', error: error.message }); + return res.status(500).json({ message: 'Error deleting API key', error: error.message }); } - }); - \ No newline at end of file +}); From ac2bc033b94c18d88687eb5ee48776b7874bd2aa Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:52:29 +0530 Subject: [PATCH 21/34] feat: spacing and center --- src/components/organisms/ApiKey.tsx | 124 +++++++++++++--------------- 1 file changed, 58 insertions(+), 66 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index d999ce76..e11b78c3 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -2,18 +2,14 @@ import React, { useState, useEffect } from 'react'; import { Box, Button, + TextField, Typography, IconButton, - CircularProgress, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, + InputAdornment, Tooltip, + CircularProgress, } from '@mui/material'; -import { ContentCopy, Visibility, Delete } from '@mui/icons-material'; +import { ContentCopy } from '@mui/icons-material'; import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -25,12 +21,29 @@ const Container = styled(Box)` margin-top: 50px; `; +const ApiKeyField = styled(TextField)` + width: 400px; + margin: 20px 0; +`; + +const HiddenText = styled(Typography)` + color: #888; + font-style: italic; +`; + +const CenteredContent = styled(Box)` + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + margin-top: 50px; /* Add top margin for spacing */ +`; + const ApiKeyManager = () => { const [apiKey, setApiKey] = useState(null); - const [apiKeyName, setApiKeyName] = useState('Maxun API Key'); const [loading, setLoading] = useState(true); - const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); + const { notify } = useGlobalInfoStore(); useEffect(() => { @@ -61,19 +74,6 @@ const ApiKeyManager = () => { } }; - const deleteApiKey = async () => { - setLoading(true); - try { - await axios.delete('http://localhost:8080/auth/delete-api-key'); - setApiKey(null); - notify('success', 'API Key deleted successfully'); - } catch (error) { - console.error('Error deleting API key', error); - } finally { - setLoading(false); - } - }; - const copyToClipboard = () => { if (apiKey) { navigator.clipboard.writeText(apiKey); @@ -89,55 +89,47 @@ const ApiKeyManager = () => { Manage Your API Key {apiKey ? ( - - - - - API Key Name - API Key - Actions - - - - - {apiKeyName} - {showKey ? apiKey : '****************'} - - - - - - - - setShowKey(!showKey)}> - - - - - - - - - - - -
- {copySuccess && ( - - Copied to Clipboard - - )} -
- ) : ( <> - You haven't generated an API key yet. - - + )} ); }; export default ApiKeyManager; + From 9104974c743bcdf906c100b370254ab4016a26e2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 04:53:28 +0530 Subject: [PATCH 22/34] feat: use Typographu --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index e11b78c3..ed6fdd24 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -116,7 +116,7 @@ const ApiKeyManager = () => { ) : ( - You haven't generated an API key yet. + You haven't generated an API key yet. - + )} ); From c6cd2626c9d12e4ac2e6971fdf7341b97bd37936 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:06:31 +0530 Subject: [PATCH 25/34] chore: lint --- src/components/organisms/ApiKey.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 8fa9707e..e79be76b 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -140,5 +140,4 @@ const ApiKeyManager = () => { ); }; -export default ApiKeyManager; - +export default ApiKeyManager; \ No newline at end of file From 4339e94ed4beb75cd8d115be5d0d3dedcbba1b07 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:09:23 +0530 Subject: [PATCH 26/34] feat: use paper for table container --- src/components/organisms/ApiKey.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index e79be76b..eba295db 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -12,6 +12,7 @@ import { TableHead, TableRow, Tooltip, + Paper, } from '@mui/material'; import { ContentCopy, Visibility, Delete } from '@mui/icons-material'; import styled from 'styled-components'; @@ -23,6 +24,7 @@ const Container = styled(Box)` flex-direction: column; align-items: center; margin-top: 50px; + margin-left: 50px; `; const ApiKeyManager = () => { @@ -89,7 +91,7 @@ const ApiKeyManager = () => { Manage Your API Key {apiKey ? ( - + From 35d2c75b15caa2089e410c925c9807f85e41218d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:10:15 +0530 Subject: [PATCH 27/34] feat: success notify --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index eba295db..179c12cb 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -55,7 +55,7 @@ const ApiKeyManager = () => { try { const { data } = await axios.post('http://localhost:8080/auth/generate-api-key'); setApiKey(data.api_key); - notify('info', `Generated API Key: ${data.api_key}`); + notify('success', `Generated API Key successfully`); } catch (error) { console.error('Error generating API key', error); } finally { From cfd7d078460170899ca4418443f6808d5e86157e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:10:49 +0530 Subject: [PATCH 28/34] feat: copied to clipboard notify --- src/components/organisms/ApiKey.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 179c12cb..7e729571 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -81,6 +81,7 @@ const ApiKeyManager = () => { navigator.clipboard.writeText(apiKey); setCopySuccess(true); setTimeout(() => setCopySuccess(false), 2000); + notify('info', 'API Key copied to clipboard'); } }; From 44523d4ddfd0f774478fad9911be8bbec4624d19 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:11:00 +0530 Subject: [PATCH 29/34] feat: copied to clipboard notify --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 7e729571..a734c307 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -81,7 +81,7 @@ const ApiKeyManager = () => { navigator.clipboard.writeText(apiKey); setCopySuccess(true); setTimeout(() => setCopySuccess(false), 2000); - notify('info', 'API Key copied to clipboard'); + notify('info', 'Copied to clipboard'); } }; From 55eebb95a6feb36333a795dcb847a4ae108493d2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:19:14 +0530 Subject: [PATCH 30/34] feat: substr api key --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index a734c307..4a41275e 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -104,7 +104,7 @@ const ApiKeyManager = () => { {apiKeyName} - {showKey ? apiKey : '****************'} + {showKey ? `${apiKey?.substring(0, 10)}...` : '****************'} From 00ff5a363529877e9e5bd24d305e91c2ebd8cabf Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:19:28 +0530 Subject: [PATCH 31/34] chore: lint --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 4a41275e..0c042db1 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -92,7 +92,7 @@ const ApiKeyManager = () => { Manage Your API Key {apiKey ? ( - +
From fa1775229e23a34748c973cb739eb30909446401 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:24:18 +0530 Subject: [PATCH 32/34] feat: increase * --- src/components/organisms/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 0c042db1..fffb62e8 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -104,7 +104,7 @@ const ApiKeyManager = () => { {apiKeyName} - {showKey ? `${apiKey?.substring(0, 10)}...` : '****************'} + {showKey ? `${apiKey?.substring(0, 10)}...` : '***************'} From d5eaaff625b1998f83b3e0264196d34672ff687c Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:24:51 +0530 Subject: [PATCH 33/34] feat: remove copy success ui --- src/components/organisms/ApiKey.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index fffb62e8..15c16393 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -125,11 +125,6 @@ const ApiKeyManager = () => {
- {copySuccess && ( - - Copied to Clipboard - - )}
) : ( <> From 329dbfc64ccda25b3a3eb4538066aa53ff39692e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:27:15 +0530 Subject: [PATCH 34/34] feat: notify errors --- src/components/organisms/ApiKey.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 15c16393..8133ae39 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -40,8 +40,8 @@ const ApiKeyManager = () => { try { const { data } = await axios.get('http://localhost:8080/auth/api-key'); setApiKey(data.api_key); - } catch (error) { - console.error('Error fetching API key', error); + } catch (error: any) { + notify('error', `Failed to fetch API Key - ${error.message}`); } finally { setLoading(false); } @@ -56,8 +56,8 @@ const ApiKeyManager = () => { const { data } = await axios.post('http://localhost:8080/auth/generate-api-key'); setApiKey(data.api_key); notify('success', `Generated API Key successfully`); - } catch (error) { - console.error('Error generating API key', error); + } catch (error: any) { + notify('error', `Failed to generate API Key - ${error.message}`); } finally { setLoading(false); } @@ -69,8 +69,8 @@ const ApiKeyManager = () => { await axios.delete('http://localhost:8080/auth/delete-api-key'); setApiKey(null); notify('success', 'API Key deleted successfully'); - } catch (error) { - console.error('Error deleting API key', error); + } catch (error: any) { + notify('error', `Failed to delete API Key - ${error.message}`); } finally { setLoading(false); }