diff --git a/back/data/open.ts b/back/data/open.ts index d5149648..2c0ba9aa 100644 --- a/back/data/open.ts +++ b/back/data/open.ts @@ -24,7 +24,7 @@ export interface AppToken { expiration: number; } -export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs'; +export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs' | 'system'; export interface AppInstance extends Model, App {} export const AppModel = sequelize.define('App', { diff --git a/back/services/open.ts b/back/services/open.ts index 5658f53c..2f63ae9c 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -159,9 +159,17 @@ export default class OpenService { value: string; expiration: number; }> { - const [systemApp] = await AppModel.findOrCreate({ - where: { name: 'system', scopes: ['crons', 'system'] }, - }); + let systemApp = ( + await AppModel.findOne({ + where: { name: 'system' }, + }) + )?.get({ plain: true }); + if (!systemApp) { + systemApp = await this.create({ + name: 'system', + scopes: ['crons', 'system'], + } as App); + } const { data } = await this.authToken({ client_id: systemApp.client_id, client_secret: systemApp.client_secret,