mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ return api key of authenticated user
This commit is contained in:
parent
be8d2c594e
commit
20087373b9
|
@ -161,7 +161,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
||||||
const ramdonToken = randomBytes(40).toString('hex');
|
const ramdonToken = randomBytes(40).toString('hex');
|
||||||
const apiKey = `n8n_api_${ramdonToken}`;
|
const apiKey = `n8n_api_${ramdonToken}`;
|
||||||
await Db.collections.User!.update(req.user.id, {
|
await Db.collections.User.update(req.user.id, {
|
||||||
apiKey,
|
apiKey,
|
||||||
});
|
});
|
||||||
return { apiKey, success: true };
|
return { apiKey, success: true };
|
||||||
|
@ -174,7 +174,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
this.app.delete(
|
this.app.delete(
|
||||||
`/${this.restEndpoint}/me/api-key`,
|
`/${this.restEndpoint}/me/api-key`,
|
||||||
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
||||||
await Db.collections.User!.update(req.user.id, {
|
await Db.collections.User.update(req.user.id, {
|
||||||
apiKey: null,
|
apiKey: null,
|
||||||
});
|
});
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
@ -187,13 +187,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
this.app.get(
|
this.app.get(
|
||||||
`/${this.restEndpoint}/me/api-key`,
|
`/${this.restEndpoint}/me/api-key`,
|
||||||
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
ResponseHelper.send(async (req: AuthenticatedRequest) => {
|
||||||
const user = await Db.collections.User!.findOne({
|
return { apiKey: req.user.apiKey };
|
||||||
where: {
|
|
||||||
apiKey: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return { apiKey: user?.apiKey };
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue