feat: use the same Authorization header for jwt and api key

This commit is contained in:
Ahmed Bouhuolia
2025-07-02 08:30:53 +02:00
parent 5d96357042
commit adb1bea374
6 changed files with 22 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import * as crypto from 'crypto';
import { ApiKeyModel } from '../models/ApiKey.model';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { AuthApiKeyPrefix } from '../Auth.constants';
@Injectable()
export class GenerateApiKey {
@@ -21,7 +22,7 @@ export class GenerateApiKey {
const user = await this.tenancyContext.getSystemUser();
// Generate a secure random API key
const key = crypto.randomBytes(48).toString('hex');
const key = `${AuthApiKeyPrefix}${crypto.randomBytes(48).toString('hex')}`;
// Save the API key to the database
const apiKeyRecord = await this.apiKeyModel.query().insert({
key,