mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
feat(core): Show Public API key value only once (no-changelog) (#10126)
This commit is contained in:
@@ -25,6 +25,8 @@ import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
import { isApiEnabled } from '@/PublicApi';
|
||||
import { EventService } from '@/eventbus/event.service';
|
||||
|
||||
export const API_KEY_PREFIX = 'n8n_api_';
|
||||
|
||||
export const isApiEnabledMiddleware: RequestHandler = (_, res, next) => {
|
||||
if (isApiEnabled()) {
|
||||
next();
|
||||
@@ -208,7 +210,8 @@ export class MeController {
|
||||
*/
|
||||
@Get('/api-key', { middlewares: [isApiEnabledMiddleware] })
|
||||
async getAPIKey(req: AuthenticatedRequest) {
|
||||
return { apiKey: req.user.apiKey };
|
||||
const apiKey = this.redactApiKey(req.user.apiKey);
|
||||
return { apiKey };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,4 +245,14 @@ export class MeController {
|
||||
|
||||
return user.settings;
|
||||
}
|
||||
|
||||
private redactApiKey(apiKey: string | null) {
|
||||
if (!apiKey) return;
|
||||
const keepLength = 5;
|
||||
return (
|
||||
API_KEY_PREFIX +
|
||||
apiKey.slice(API_KEY_PREFIX.length, API_KEY_PREFIX.length + keepLength) +
|
||||
'*'.repeat(apiKey.length - API_KEY_PREFIX.length - keepLength)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user