@@ -2,30 +2,26 @@ import {
22 FastifyPluginAsyncTypebox ,
33 Type ,
44} from '@fastify/type-provider-typebox' ;
5- import { IdentityClient } from '@frontegg/client' ;
65import { AppSystemProp , logger , system } from '@openops/server-shared' ;
76import { ALL_PRINCIPAL_TYPES , OpenOpsId } from '@openops/shared' ;
8- import { getCloudToken , getCloudUser } from '../user-info/cloud-auth' ;
7+ import { getVerifiedUser } from '../user-info/cloud-auth' ;
98import { flowTemplateService } from './flow-template.service' ;
109
1110export const cloudTemplateController : FastifyPluginAsyncTypebox = async (
1211 app ,
1312) => {
14- const fronteggClientId = system . get ( AppSystemProp . FRONTEGG_CLIENT_ID ) ;
15- const fronteggApiKey = system . get ( AppSystemProp . FRONTEGG_API_KEY ) ;
13+ const publicKey = system . get ( AppSystemProp . FRONTEGG_PUBLIC_KEY ) ;
14+ const connectionPageEnabled = system . getBoolean (
15+ AppSystemProp . CLOUD_CONNECTION_PAGE_ENABLED ,
16+ ) ;
1617
17- if ( ! fronteggClientId || ! fronteggApiKey ) {
18+ if ( ! publicKey || ! connectionPageEnabled ) {
1819 logger . info (
1920 'Missing Frontegg configuration, disabling cloud templates API' ,
2021 ) ;
2122 return ;
2223 }
2324
24- const identityClient = new IdentityClient ( {
25- FRONTEGG_CLIENT_ID : fronteggClientId ,
26- FRONTEGG_API_KEY : fronteggApiKey ,
27- } ) ;
28-
2925 // cloud templates are available on any origin
3026 app . addHook ( 'onSend' , ( request , reply , payload , done ) => {
3127 void reply . header (
@@ -38,7 +34,6 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
3834 'Content-Type,Ops-Origin,Authorization' ,
3935 ) ;
4036 void reply . header ( 'Access-Control-Allow-Credentials' , 'true' ) ;
41-
4237 if ( request . method === 'OPTIONS' ) {
4338 return reply . status ( 204 ) . send ( ) ;
4439 }
@@ -70,9 +65,8 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
7065 } ,
7166 } ,
7267 async ( request ) => {
73- const token = getCloudToken ( request ) ;
74-
75- if ( ! ( await getCloudUser ( identityClient , token ) ) ) {
68+ const user = getVerifiedUser ( request , publicKey ) ;
69+ if ( ! user ) {
7670 return flowTemplateService . getFlowTemplates ( {
7771 search : request . query . search ,
7872 tags : request . query . tags ,
@@ -120,8 +114,9 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
120114 } ,
121115 } ,
122116 async ( request , reply ) => {
123- const token = getCloudToken ( request ) ;
124- if ( ! ( await getCloudUser ( identityClient , token ) ) ) {
117+ const user = getVerifiedUser ( request , publicKey ) ;
118+
119+ if ( ! user ) {
125120 const template = await flowTemplateService . getFlowTemplate (
126121 request . params . id ,
127122 ) ;
0 commit comments