@@ -76,6 +76,7 @@ import { findProjectBySlug } from "~/models/project.server";
7676import { findEnvironmentBySlug } from "~/models/runtimeEnvironment.server" ;
7777import { ApiKeysPresenter } from "~/presenters/v3/ApiKeysPresenter.server" ;
7878import { FULL_ACCESS_PRESET_ID } from "@trigger.dev/rbac" ;
79+ import { canIssueAdditionalApiKeys } from "~/services/additionalApiKeyIssuance.server" ;
7980import { rbac } from "~/services/rbac.server" ;
8081import { dashboardAction , dashboardLoader } from "~/services/routeBuilders/dashboardBuilder" ;
8182import { cn } from "~/utils/cn" ;
@@ -180,16 +181,21 @@ export const loader = dashboardLoader(
180181 return organizationId ? { organizationId } : { } ;
181182 } ,
182183 } ,
183- async ( { params, searchParams, user, ability } ) => {
184+ async ( { params, searchParams, user, ability, context } ) => {
184185 try {
185186 const presenter = new ApiKeysPresenter ( ) ;
186- const data = await presenter . call ( {
187- userId : user . id ,
188- organizationSlug : params . organizationSlug ,
189- projectSlug : params . projectParam ,
190- environmentSlug : params . envParam ,
191- showRevoked : searchParams . showRevoked ,
192- } ) ;
187+ const [ data , additionalApiKeyIssuanceEnabled ] = await Promise . all ( [
188+ presenter . call ( {
189+ userId : user . id ,
190+ organizationSlug : params . organizationSlug ,
191+ projectSlug : params . projectParam ,
192+ environmentSlug : params . envParam ,
193+ showRevoked : searchParams . showRevoked ,
194+ } ) ,
195+ context . organizationId
196+ ? canIssueAdditionalApiKeys ( context . organizationId )
197+ : Promise . resolve ( false ) ,
198+ ] ) ;
193199
194200 const canReadApiKeys = ability . can ( "read" , {
195201 type : "apiKeys" ,
@@ -214,6 +220,7 @@ export const loader = dashboardLoader(
214220 apiKeys : canReadApiKeys ? data . apiKeys : [ ] ,
215221 canReadApiKeys,
216222 canWriteApiKeys,
223+ additionalApiKeyIssuanceEnabled,
217224 showRevoked : searchParams . showRevoked ?? false ,
218225 } ) ;
219226 } catch ( error ) {
@@ -276,6 +283,15 @@ export const action = dashboardAction(
276283 try {
277284 switch ( submission . data . action ) {
278285 case "create" : {
286+ if ( ! ( await canIssueAdditionalApiKeys ( project . organizationId ) ) ) {
287+ const message = "Creating additional API keys is not enabled." ;
288+ return typedJsonWithErrorMessage (
289+ { ok : false as const , error : message } ,
290+ request ,
291+ message
292+ ) ;
293+ }
294+
279295 const presets = await rbac . apiKeyPresets ( project . organizationId ) ;
280296 const preset = validateCreateApiKeyPreset ( {
281297 presets,
@@ -335,6 +351,7 @@ export default function Page() {
335351 apiKeys,
336352 canReadApiKeys,
337353 canWriteApiKeys,
354+ additionalApiKeyIssuanceEnabled,
338355 showRevoked,
339356 hasVercelIntegration,
340357 availableTasks,
@@ -370,7 +387,7 @@ export default function Page() {
370387 API keys docs
371388 </ LinkButton >
372389
373- { canReadApiKeys ? (
390+ { canReadApiKeys && additionalApiKeyIssuanceEnabled ? (
374391 < NewApiKeyDialog
375392 canWrite = { canWriteApiKeys }
376393 availableTasks = { availableTasks }
@@ -503,7 +520,7 @@ export default function Page() {
503520 apiKey . createdBy ?. displayName ??
504521 apiKey . createdBy ?. name ??
505522 apiKey . createdBy ?. email ??
506- "Deleted user " ;
523+ "– " ;
507524
508525 return (
509526 < TableRow key = { apiKey . id } disabled = { cannotAuthenticate } >
@@ -653,10 +670,10 @@ function NewApiKeyDialog({
653670 className = "w-full"
654671 />
655672 < Callout variant = "warning" >
656- Requires a version of < InlineCode variant = "extra-small" > @trigger.dev/sdk</ InlineCode > { " " }
657- that supports additional environment API keys. On older versions, { " " }
658- < InlineCode variant = "extra-small" > auth.createPublicToken()</ InlineCode > will return a
659- token the server rejects, because only the root API key can sign one locally .
673+ Use < InlineCode variant = "extra-small" > @trigger.dev/sdk</ InlineCode > v4.5.8 or later.
674+ Older SDK versions mint an unusable token when { " " }
675+ < InlineCode variant = "extra-small" > auth.createPublicToken()</ InlineCode > is called with
676+ this API key.
660677 </ Callout >
661678 < FormButtons
662679 confirmButton = {
0 commit comments