Skip to content

Conversation

@amhsirak
Copy link
Member

@amhsirak amhsirak commented Dec 29, 2025

Summary by CodeRabbit

  • New Features
    • API keys now display their creation date and time with a new "Created On" column
    • Timestamps are automatically tracked whenever API keys are generated, deleted, or retrieved

✏️ Tip: You can customize this high-level summary in your review settings.

@amhsirak amhsirak requested a review from RohitR311 December 29, 2025 19:10
@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

Walkthrough

This PR adds API key creation timestamp tracking to the system. The User model gains an optional api_key_created_at field, auth endpoints now record and return this timestamp when generating, retrieving, or deleting API keys, and the frontend UI displays the creation date in a new table column.

Changes

Cohort / File(s) Summary
Backend Model & Database
server/src/models/User.ts
Added optional api_key_created_at DATE column to User model with allowNull: true. Extends UserAttributes interface and Sequelize initialization.
Backend Auth Routes
server/src/routes/auth.ts
Modified generate-api-key, api-key fetch, and delete-api-key endpoints to respectively set, return, and clear api_key_created_at. Persists timestamp on user updates.
Frontend API Key Component
src/components/api/ApiKey.tsx
Added apiKeyCreatedAt state variable, propagated timestamp from API responses across fetch/generate/delete operations, and rendered conditional "Created On" table column with formatted date display.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #452: Both PRs modify server/src/routes/auth.ts endpoints with overlapping response field handling and persistence logic.

Suggested labels

Type: Enhancement

Poem

🐰 A key is born, timestamp in tow,
Tracking when each secret started to grow,
From database rows to the UI's display,
Creation dates gleam in their column of day! 🗝️✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding display of API key creation date across the backend and frontend components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/components/api/ApiKey.tsx (1)

151-159: Consider using the i18n locale for date formatting.

The date locale is hardcoded to 'en-US', which may not match the user's language preference configured through i18n.

💡 Suggested improvement

Extract the current locale from i18n and use it for date formatting:

+  const { i18n } = useTranslation();
+
   // ... inside the TableCell rendering:
-                    {new Date(apiKeyCreatedAt).toLocaleDateString('en-US', {
+                    {new Date(apiKeyCreatedAt).toLocaleDateString(i18n.language, {
                       month: 'short',
                       day: 'numeric',
                       year: 'numeric',
                     })}

This ensures date formatting aligns with the user's selected language.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between adfb12e and 0006165.

📒 Files selected for processing (3)
  • server/src/models/User.ts
  • server/src/routes/auth.ts
  • src/components/api/ApiKey.tsx
🔇 Additional comments (6)
server/src/models/User.ts (1)

10-10: LGTM! Model field definitions are consistent.

The api_key_created_at field is properly defined across the TypeScript interface and class with appropriate nullable typing.

Also applies to: 24-24

server/src/routes/auth.ts (3)

258-270: LGTM! API key creation timestamp is properly captured and persisted.

The implementation correctly creates a timestamp, persists it to the database, and returns it in the response.


295-310: LGTM! Fetch endpoint properly retrieves and returns the creation timestamp.

The api_key_created_at field is correctly included in the query attributes and response payload.


342-342: LGTM! Delete operation properly clears the creation timestamp.

Clearing both api_key and api_key_created_at together maintains data consistency.

src/components/api/ApiKey.tsx (2)

37-37: LGTM! State management for the creation timestamp is correct.

The apiKeyCreatedAt state is properly initialized, updated across all API operations (fetch, generate, delete), and cleared when appropriate.

Also applies to: 48-48, 65-65, 79-79


134-134: Table layout change looks appropriate.

Setting tableLayout: 'fixed' with width: '100%' provides consistent column sizing and better handles the conditional "Created On" column.

Comment on lines +58 to +61
api_key_created_at: {
type: DataTypes.DATE,
allowNull: true,
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for migration files that add api_key_created_at column
rg -n -C3 'api_key_created_at|addColumn.*api_key' --type=js --type=ts

Repository: getmaxun/maxun

Length of output: 4624


🏁 Script executed:

#!/bin/bash
# Find migration directory structure
find . -type d -name "*migration*" -o -type d -name "*migrate*" | head -20

Repository: getmaxun/maxun

Length of output: 84


🏁 Script executed:

#!/bin/bash
# List migration files
git ls-files | grep -i -E "(migration|migrate)" | head -30

Repository: getmaxun/maxun

Length of output: 202


🏁 Script executed:

#!/bin/bash
# Check the content of migration files
echo "=== Checking add-airtable-columns.js ==="
cat server/src/db/migrations/20250327111003-add-airtable-columns.js

echo -e "\n=== Checking add-webhooks.js ==="
cat server/src/db/migrations/20250527105655-add-webhooks.js

Repository: getmaxun/maxun

Length of output: 4133


🏁 Script executed:

#!/bin/bash
# Check if there are any older migrations that might have created api_key columns
ls -la server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 336


🏁 Script executed:

#!/bin/bash
# Search for any initial database setup or schema files that might define api_key columns
find . -type f -name "*.sql" -o -name "*schema*" -o -name "*setup*" | grep -E "(db|migration|schema)" | head -20

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

#!/bin/bash
# Check the migrate.js file which might be the entry point for migrations
cat server/src/db/migrate.js

Repository: getmaxun/maxun

Length of output: 884


🏁 Script executed:

#!/bin/bash
# Search for any reference to api_key in migration files
rg -n "api_key" server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

#!/bin/bash
# Check for seeders or initial setup scripts
ls -la server/src/db/seeders/ 2>/dev/null || echo "No seeders directory found"

# Check if api_key columns exist in initial User model definition
grep -n "api_key" server/src/models/User.ts | head -20

Repository: getmaxun/maxun

Length of output: 405


🏁 Script executed:

#!/bin/bash
# Search for any .sequelizerc or sequelize config that might handle migrations
find . -name ".sequelizerc" -o -name "sequelize-config*" -o -name "database.json" 2>/dev/null | head -10

Repository: getmaxun/maxun

Length of output: 72


🏁 Script executed:

#!/bin/bash
# Check the sequelize configuration
cat .sequelizerc

Repository: getmaxun/maxun

Length of output: 349


🏁 Script executed:

#!/bin/bash
# Look for any other migration-related configuration
cat server/src/db/models/index.js | head -100

Repository: getmaxun/maxun

Length of output: 1645


A database migration for the api_key columns is missing.

The User model defines api_key_name, api_key, and api_key_created_at columns (lines 49-61), and these are actively used in server/src/routes/auth.ts, but no migration exists to add these columns to the database. Existing databases will fail when the code attempts to read or write these fields.

Create a migration file in server/src/db/migrations/ (e.g., 20250101000000-add-api-key-columns.js):

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.addColumn('user', 'api_key_name', {
        type: Sequelize.STRING,
        allowNull: true,
      }, { transaction });
      
      await queryInterface.addColumn('user', 'api_key', {
        type: Sequelize.STRING,
        allowNull: true,
      }, { transaction });
      
      await queryInterface.addColumn('user', 'api_key_created_at', {
        type: Sequelize.DATE,
        allowNull: true,
      }, { transaction });
      
      await transaction.commit();
    } catch (error) {
      await transaction.rollback();
      throw error;
    }
  },

  down: async (queryInterface, Sequelize) => {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.removeColumn('user', 'api_key_created_at', { transaction });
      await queryInterface.removeColumn('user', 'api_key', { transaction });
      await queryInterface.removeColumn('user', 'api_key_name', { transaction });
      await transaction.commit();
    } catch (error) {
      await transaction.rollback();
      throw error;
    }
  }
};
🤖 Prompt for AI Agents
In server/src/models/User.ts around lines 58 to 61, the model adds api_key_name,
api_key, and api_key_created_at fields but there is no DB migration; create a
new migration file under server/src/db/migrations (e.g.,
20250101000000-add-api-key-columns.js) that in up() opens a transaction and adds
the three columns to the user table (api_key_name: Sequelize.STRING allowNull:
true; api_key: Sequelize.STRING allowNull: true; api_key_created_at:
Sequelize.DATE allowNull: true) and commits, and in down() removes those columns
in reverse order within a transaction and commits (rollback on error).
<TableCell>{t('apikey.table.name')}</TableCell>
<TableCell>{t('apikey.table.key')}</TableCell>
<TableCell>{t('apikey.table.actions')}</TableCell>
{apiKeyCreatedAt && <TableCell>Created On</TableCell>}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use i18n for the "Created On" column header.

The "Created On" text is hardcoded while other table headers use the t() function for internationalization.

🔎 Proposed fix
-                {apiKeyCreatedAt && <TableCell>Created On</TableCell>}
+                {apiKeyCreatedAt && <TableCell>{t('apikey.table.created_on')}</TableCell>}

Don't forget to add the translation key to your i18n resource files.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{apiKeyCreatedAt && <TableCell>Created On</TableCell>}
{apiKeyCreatedAt && <TableCell>{t('apikey.table.created_on')}</TableCell>}
🤖 Prompt for AI Agents
In src/components/api/ApiKey.tsx around line 139 the "Created On" table header
is hardcoded; replace it with the i18n helper used elsewhere (e.g.,
t('createdOn') or the appropriate key in the same namespace as other headers)
and ensure you add that translation key and value to the i18n resource files for
all supported locales.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants