From 27b188170e868add9dd9a7df3070752cdb59d2c0 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:27:47 +0530 Subject: [PATCH 1/7] feat: store api_key_created_at --- server/src/models/User.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 6664f381..1076bc07 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -7,6 +7,7 @@ interface UserAttributes { password: string; api_key_name?: string | null; api_key?: string | null; + api_key_created_at?: Date | null; proxy_url?: string | null; proxy_username?: string | null; proxy_password?: string | null; @@ -20,6 +21,7 @@ class User extends Model implements User public password!: string; public api_key_name!: string | null; public api_key!: string | null; + public api_key_created_at!: Date | null; public proxy_url!: string | null; public proxy_username!: string | null; public proxy_password!: string | null; @@ -53,6 +55,10 @@ User.init( type: DataTypes.STRING, allowNull: true, }, + api_key_created_at: { + type: DataTypes.DATE, + allowNull: true, + }, proxy_url: { type: DataTypes.STRING, allowNull: true, From afd4a63249cd53117ff56321ed905f16267accfb Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:31:51 +0530 Subject: [PATCH 2/7] feat: create, store, fetch api key create date --- server/src/routes/auth.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 5a758ee9..4ddbafe1 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -255,8 +255,9 @@ router.post( return res.status(400).json({ message: "API key already exists" }); } const apiKey = genAPIKey(); + const createdAt = new Date(); - await user.update({ api_key: apiKey }); + await user.update({ api_key: apiKey, api_key_created_at: createdAt }) capture("maxun-oss-api-key-created", { user_id: user.id, @@ -266,6 +267,7 @@ router.post( return res.status(200).json({ message: "API key generated successfully", api_key: apiKey, + api_key_created_at: createdAt, }); } catch (error) { return res @@ -290,7 +292,7 @@ router.get( const user = await User.findByPk(req.user.id, { raw: true, - attributes: ["api_key"], + attributes: ["api_key", "api_key_created_at"] }); if (!user) { @@ -305,6 +307,7 @@ router.get( ok: true, message: "API key fetched successfully", api_key: user.api_key || null, + api_key_created_at: user.api_key_created_at || null, }); } catch (error) { console.error('API Key fetch error:', error); @@ -336,7 +339,7 @@ router.delete( return res.status(404).json({ message: "API Key not found" }); } - await User.update({ api_key: null }, { where: { id: req.user.id } }); + await User.update({ api_key: null, api_key_created_at: null }, { where: { id: req.user.id } }); capture("maxun-oss-api-key-deleted", { user_id: user.id, From 495d440ce638bbb4755674d6c7ca8cddeed99a11 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:34:10 +0530 Subject: [PATCH 3/7] feat: show api key created on --- src/components/api/ApiKey.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/api/ApiKey.tsx b/src/components/api/ApiKey.tsx index 27897169..73916d1e 100644 --- a/src/components/api/ApiKey.tsx +++ b/src/components/api/ApiKey.tsx @@ -34,6 +34,7 @@ const ApiKeyManager = () => { const { t } = useTranslation(); const [apiKey, setApiKey] = useState(null); const [apiKeyName, setApiKeyName] = useState(t('apikey.default_name')); + const [apiKeyCreatedAt, setApiKeyCreatedAt] = useState(null); const [loading, setLoading] = useState(true); const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); @@ -44,6 +45,7 @@ const ApiKeyManager = () => { try { const { data } = await axios.get(`${apiUrl}/auth/api-key`); setApiKey(data.api_key); + setApiKeyCreatedAt(data.api_key_created_at); } catch (error: any) { notify('error', t('apikey.notifications.fetch_error', { error: error.message })); } finally { @@ -60,7 +62,7 @@ const ApiKeyManager = () => { try { const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`); setApiKey(data.api_key); - + setApiKeyCreatedAt(data.api_key_created_at); notify('success', t('apikey.notifications.generate_success')); } catch (error: any) { notify('error', t('apikey.notifications.generate_error', { error: error.message })); @@ -74,6 +76,7 @@ const ApiKeyManager = () => { try { await axios.delete(`${apiUrl}/auth/delete-api-key`); setApiKey(null); + setApiKeyCreatedAt(null); notify('success', t('apikey.notifications.delete_success')); } catch (error: any) { notify('error', t('apikey.notifications.delete_error', { error: error.message })); @@ -133,6 +136,7 @@ const ApiKeyManager = () => { {t('apikey.table.name')} {t('apikey.table.key')} + Created On {t('apikey.table.actions')} @@ -144,6 +148,15 @@ const ApiKeyManager = () => { {showKey ? `${apiKey?.substring(0, 10)}...` : '**********'} + {apiKeyCreatedAt && ( + + {new Date(apiKeyCreatedAt).toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + })} + + )} From 7ef961d3da927221e28e0d39e33a1760e27f12e7 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:34:36 +0530 Subject: [PATCH 4/7] fix: align all actions to right end --- src/components/api/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/api/ApiKey.tsx b/src/components/api/ApiKey.tsx index 73916d1e..413d866c 100644 --- a/src/components/api/ApiKey.tsx +++ b/src/components/api/ApiKey.tsx @@ -157,7 +157,7 @@ const ApiKeyManager = () => { })} )} - + From 1bc3f02d9b8f11cac69c32360aecab3fed89f756 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:34:58 +0530 Subject: [PATCH 5/7] fix: align all actions to right end --- src/components/api/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/api/ApiKey.tsx b/src/components/api/ApiKey.tsx index 413d866c..3feb590d 100644 --- a/src/components/api/ApiKey.tsx +++ b/src/components/api/ApiKey.tsx @@ -131,7 +131,7 @@ const ApiKeyManager = () => { {apiKey ? ( - +
{t('apikey.table.name')} From d1e0164047cccdddc2f858e7fb1a2a40bcc63b80 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:35:34 +0530 Subject: [PATCH 6/7] fix: align actions name table cell to center --- src/components/api/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/api/ApiKey.tsx b/src/components/api/ApiKey.tsx index 3feb590d..fc81aecb 100644 --- a/src/components/api/ApiKey.tsx +++ b/src/components/api/ApiKey.tsx @@ -137,7 +137,7 @@ const ApiKeyManager = () => { {t('apikey.table.name')} {t('apikey.table.key')} Created On - {t('apikey.table.actions')} + {t('apikey.table.actions')} From 0006165f1ac166707dafc97eded87215d5db517b Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 30 Dec 2025 00:37:37 +0530 Subject: [PATCH 7/7] fix: show created on col if apiKeyCreatedAt exists --- src/components/api/ApiKey.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/api/ApiKey.tsx b/src/components/api/ApiKey.tsx index fc81aecb..73f95dc7 100644 --- a/src/components/api/ApiKey.tsx +++ b/src/components/api/ApiKey.tsx @@ -136,7 +136,7 @@ const ApiKeyManager = () => { {t('apikey.table.name')} {t('apikey.table.key')} - Created On + {apiKeyCreatedAt && Created On} {t('apikey.table.actions')}