-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: display api key creation date #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis PR adds API key creation timestamp tracking to the system. The User model gains an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this 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
📒 Files selected for processing (3)
server/src/models/User.tsserver/src/routes/auth.tssrc/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_atfield 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_atfield is correctly included in the query attributes and response payload.
342-342: LGTM! Delete operation properly clears the creation timestamp.Clearing both
api_keyandapi_key_created_attogether maintains data consistency.src/components/api/ApiKey.tsx (2)
37-37: LGTM! State management for the creation timestamp is correct.The
apiKeyCreatedAtstate 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'withwidth: '100%'provides consistent column sizing and better handles the conditional "Created On" column.
| api_key_created_at: { | ||
| type: DataTypes.DATE, | ||
| allowNull: true, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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=tsRepository: 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 -20Repository: getmaxun/maxun
Length of output: 84
🏁 Script executed:
#!/bin/bash
# List migration files
git ls-files | grep -i -E "(migration|migrate)" | head -30Repository: 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.jsRepository: 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 -20Repository: 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.jsRepository: 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 -20Repository: 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 -10Repository: getmaxun/maxun
Length of output: 72
🏁 Script executed:
#!/bin/bash
# Check the sequelize configuration
cat .sequelizercRepository: 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 -100Repository: 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>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| {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.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.