mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: use the same Authorization header for jwt and api key
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user