mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
⚡ Improvements to api-key endpoints
This commit is contained in:
parent
d6d4220a17
commit
5d1838ccf5
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable import/no-cycle */
|
||||
|
||||
import express from 'express';
|
||||
|
@ -158,7 +159,7 @@ export function meNamespace(this: N8nApp): void {
|
|||
this.app.post(
|
||||
`/${this.restEndpoint}/users/me/api-key`,
|
||||
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
||||
const ramdonToken = randomBytes(20).toString('hex');
|
||||
const ramdonToken = randomBytes(40).toString('hex');
|
||||
const apiKey = `n8n_api_${ramdonToken}`;
|
||||
await Db.collections.User!.update(req.user.id, {
|
||||
apiKey,
|
||||
|
@ -183,18 +184,16 @@ export function meNamespace(this: N8nApp): void {
|
|||
/**
|
||||
* Get an API Key
|
||||
*/
|
||||
this.app.delete(
|
||||
this.app.get(
|
||||
`/${this.restEndpoint}/me/api-key`,
|
||||
ResponseHelper.send(async () => {
|
||||
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
||||
const user = await Db.collections.User!.findOne({
|
||||
where: {
|
||||
apiKey: null,
|
||||
},
|
||||
});
|
||||
|
||||
if (user) {
|
||||
return { apiKey: user.apiKey, success: true };
|
||||
}
|
||||
return { apiKey: user?.apiKey };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue