feat: api keys ui (#839)

* feat: api keys ui
This commit is contained in:
Ahmed Bouhuolia
2025-11-02 12:41:16 +02:00
committed by GitHub
parent 41143d8bbd
commit a76445a6eb
23 changed files with 723 additions and 11 deletions

View File

@@ -10,14 +10,15 @@ export class GenerateApiKey {
private readonly tenancyContext: TenancyContext,
@Inject(ApiKeyModel.name)
private readonly apiKeyModel: typeof ApiKeyModel,
) {}
) { }
/**
* Generates a new secure API key for the current tenant and system user.
* The key is saved in the database and returned (only the key and id for security).
* @param {string} name - Optional name for the API key.
* @returns {Promise<{ key: string; id: number }>} The generated API key and its database id.
*/
async generate() {
async generate(name?: string) {
const tenant = await this.tenancyContext.getTenant();
const user = await this.tenancyContext.getSystemUser();
@@ -26,6 +27,7 @@ export class GenerateApiKey {
// Save the API key to the database
const apiKeyRecord = await this.apiKeyModel.query().insert({
key,
name,
tenantId: tenant.id,
userId: user.id,
createdAt: new Date(),