Merge pull request #935 from getmaxun/api-key-create

feat: display api key creation date
This commit is contained in:
Karishma Shukla
2026-01-04 18:11:19 +05:30
committed by GitHub
3 changed files with 29 additions and 7 deletions

View File

@@ -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<UserAttributes, UserCreationAttributes> 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,

View File

@@ -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,