Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mcpServers": {
"trigger": {
"command": "npx",
"args": [
"trigger.dev@latest",
"mcp",
"--dev-only"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { encrypt } from '@/lib/encryption';
import { getIntegrationHandler } from '@comp/integrations';
import { db } from '@db';
import { revalidatePath } from 'next/cache';
import { headers } from 'next/headers';
import { cookies, headers } from 'next/headers';
import { z } from 'zod';
import { authActionClient } from '../../../../../actions/safe-action';
import { runTests } from './run-tests';
Expand Down Expand Up @@ -100,7 +100,11 @@ export const connectCloudAction = authActionClient
}

// Trigger immediate scan
await runTests();
const runResult = await runTests();

if (runResult.success && runResult.publicAccessToken) {
(await cookies()).set('publicAccessToken', runResult.publicAccessToken);
}

// Revalidate the path
const headersList = await headers();
Expand All @@ -110,6 +114,13 @@ export const connectCloudAction = authActionClient

return {
success: true,
trigger: runResult.success
? {
taskId: runResult.taskId ?? undefined,
publicAccessToken: runResult.publicAccessToken ?? undefined,
}
: undefined,
runErrors: runResult.success ? undefined : (runResult.errors ?? undefined),
};
} catch (error) {
console.error('Failed to connect cloud provider:', error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use server';

import { auth as betterAuth } from '@/utils/auth';
import { auth } from '@trigger.dev/sdk';
import { headers } from 'next/headers';

export const createTriggerToken = async () => {
const session = await betterAuth.api.getSession({
headers: await headers(),
});

if (!session) {
return {
success: false,
error: 'Unauthorized',
};
}

const orgId = session.session?.activeOrganizationId;
if (!orgId) {
return {
success: false,
error: 'No active organization',
};
}

try {
const token = await auth.createTriggerPublicToken('run-integration-tests', {
multipleUse: true,
expirationTime: '1hr',
});

return {
success: true,
token,
};
} catch (error) {
console.error('Error creating trigger token:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Failed to create trigger token',
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface CloudField {
type?: string;
}

type TriggerInfo = {
taskId?: string;
publicAccessToken?: string;
};

interface CloudConnectionCardProps {
cloudProvider: 'aws' | 'gcp' | 'azure';
name: string;
Expand All @@ -27,7 +32,7 @@ interface CloudConnectionCardProps {
guideUrl?: string;
color?: string;
logoUrl?: string;
onSuccess?: () => void;
onSuccess?: (trigger?: TriggerInfo) => void;
}

export function CloudConnectionCard({
Expand Down Expand Up @@ -83,7 +88,11 @@ export function CloudConnectionCard({
if (result?.data?.success) {
toast.success(`${name} connected! Running initial scan...`);
setCredentials({});
onSuccess?.();
onSuccess?.(result.data?.trigger);

if (result.data?.runErrors && result.data.runErrors.length > 0) {
toast.error(result.data.runErrors[0] || 'Initial scan reported an issue');
}
} else {
toast.error(result?.data?.error || 'Failed to connect');
}
Expand All @@ -99,13 +108,11 @@ export function CloudConnectionCard({
<Card className="rounded-xs">
<CardHeader className="space-y-4">
<div className="flex items-center gap-3">
<div className={`bg-gradient-to-br ${color} flex items-center justify-center rounded-lg p-2`}>
<div
className={`bg-gradient-to-br ${color} flex items-center justify-center rounded-lg p-2`}
>
{logoUrl && (
<img
src={logoUrl}
alt={`${shortName} logo`}
className="h-8 w-8 object-contain"
/>
<img src={logoUrl} alt={`${shortName} logo`} className="h-8 w-8 object-contain" />
)}
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,18 @@ const PROVIDER_FIELDS: Record<'aws' | 'gcp' | 'azure', ProviderFieldWithOptions[
],
};

type TriggerInfo = {
taskId?: string;
publicAccessToken?: string;
};

interface EmptyStateProps {
onBack?: () => void;
connectedProviders?: string[];
onConnected?: (trigger?: TriggerInfo) => void;
}

export function EmptyState({ onBack, connectedProviders = [] }: EmptyStateProps = {}) {
export function EmptyState({ onBack, connectedProviders = [], onConnected }: EmptyStateProps = {}) {
const [step, setStep] = useState<Step>('choose');
const [selectedProvider, setSelectedProvider] = useState<CloudProvider>(null);
const [credentials, setCredentials] = useState<Record<string, string>>({});
Expand Down Expand Up @@ -224,6 +230,12 @@ export function EmptyState({ onBack, connectedProviders = [] }: EmptyStateProps

if (result?.data?.success) {
setStep('success');
if (result.data?.trigger) {
onConnected?.(result.data.trigger);
}
if (result.data?.runErrors && result.data.runErrors.length > 0) {
toast.error(result.data.runErrors[0] || 'Initial scan reported an issue');
}
// If user already has clouds, automatically return to results after 2 seconds
if (onBack) {
setTimeout(() => {
Expand Down
Loading
Loading