fix: Do not create oauth clients for non-supported apps

This commit is contained in:
Faruk AYDIN
2025-01-22 17:37:59 +01:00
parent e686d3b067
commit ede745495d
3 changed files with 53 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import App from './app.js';
import OAuthClient from './oauth-client.js';
import Base from './base.js';
import { ValidationError } from 'objection';
class AppConfig extends Base {
static tableName = 'app_configs';
@@ -39,6 +40,27 @@ class AppConfig extends Base {
return await App.findOneByKey(this.key);
}
async createOAuthClient(params) {
const supportsOauthClients = (await this.getApp())?.auth?.generateAuthUrl
? true
: false;
if (!supportsOauthClients) {
throw new ValidationError({
data: {
app: [
{
message: 'This app does not support OAuth clients!',
},
],
},
type: 'ModelValidation',
});
}
return await this.$relatedQuery('oauthClients').insert(params);
}
}
export default AppConfig;