mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
feat(onboarding): compute edgeKey directly on the server side to avoid lazy loading
This commit is contained in:
@@ -5,6 +5,8 @@ import { useOnboarding } from "@onboardjs/react";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { createAgentAction } from "@/features/agents/agents.action";
|
import { createAgentAction } from "@/features/agents/agents.action";
|
||||||
import type { OnboardingAgent, OnboardingDefaultsData } from "@/features/onboarding/types";
|
import type { OnboardingAgent, OnboardingDefaultsData } from "@/features/onboarding/types";
|
||||||
|
import { generateEdgeKey } from "@/utils/edge_key";
|
||||||
|
import { getServerUrl } from "@/utils/get-server-url";
|
||||||
|
|
||||||
export const useCreateAgent = () => {
|
export const useCreateAgent = () => {
|
||||||
const { state, updateContext } = useOnboarding();
|
const { state, updateContext } = useOnboarding();
|
||||||
@@ -23,9 +25,12 @@ export const useCreateAgent = () => {
|
|||||||
throw new Error(result?.serverError ?? `Failed to create agent "${name}"`);
|
throw new Error(result?.serverError ?? `Failed to create agent "${name}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const edgeKey = await generateEdgeKey(getServerUrl(), result.data.data.id);
|
||||||
|
|
||||||
const newAgent: OnboardingAgent = {
|
const newAgent: OnboardingAgent = {
|
||||||
id: result.data.data.id,
|
id: result.data.data.id,
|
||||||
name: result.data.data.name,
|
name: result.data.data.name,
|
||||||
|
edgeKey,
|
||||||
notifierId: defaults.notifierId,
|
notifierId: defaults.notifierId,
|
||||||
storageId: defaults.storageId,
|
storageId: defaults.storageId,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import type {
|
|||||||
OnboardingFlowData,
|
OnboardingFlowData,
|
||||||
OnboardingMeta,
|
OnboardingMeta,
|
||||||
} from "@/features/onboarding/types";
|
} from "@/features/onboarding/types";
|
||||||
|
import { generateEdgeKey } from "@/utils/edge_key";
|
||||||
|
import { getServerUrl } from "@/utils/get-server-url";
|
||||||
|
|
||||||
export type ResolvedOnboardingState =
|
export type ResolvedOnboardingState =
|
||||||
| { redirect: "/dashboard/home" }
|
| { redirect: "/dashboard/home" }
|
||||||
@@ -86,7 +88,13 @@ export async function resolveOnboardingState(): Promise<ResolvedOnboardingState>
|
|||||||
storageId: settings?.defaultStorageChannelId ?? undefined,
|
storageId: settings?.defaultStorageChannelId ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const agentData = (agents ?? []).map((a) => ({ id: a.id, name: a.name }));
|
const agentData = await Promise.all(
|
||||||
|
(agents ?? []).map(async (a) => ({
|
||||||
|
id: a.id,
|
||||||
|
name: a.name,
|
||||||
|
edgeKey: await generateEdgeKey(getServerUrl(), a.id),
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
const databases = (agents as AgentWith[]).flatMap((a) =>
|
const databases = (agents as AgentWith[]).flatMap((a) =>
|
||||||
(a.databases ?? []).map((d) => ({
|
(a.databases ?? []).map((d) => ({
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { useOnboarding } from "@onboardjs/react";
|
|||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CodeSnippet } from "@/components/common/code-snippet";
|
import { CodeSnippet } from "@/components/common/code-snippet";
|
||||||
import { useGenerateEdgeKey } from "@/features/onboarding/hooks/use-generate-edge-key";
|
|
||||||
import type { OnboardingAgent } from "@/features/onboarding/types";
|
import type { OnboardingAgent } from "@/features/onboarding/types";
|
||||||
|
|
||||||
export const StepAgentKey = () => {
|
export const StepAgentKey = () => {
|
||||||
@@ -30,24 +29,22 @@ export const StepAgentKey = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const AgentKeyBlock = ({ agent }: { agent: OnboardingAgent }) => {
|
const AgentKeyBlock = ({ agent }: { agent: OnboardingAgent }) => {
|
||||||
const { data, isLoading } = useGenerateEdgeKey(agent.id);
|
if (!agent.edgeKey) {
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex items-center gap-2 text-sm text-muted-foreground p-4 rounded-lg border border-border bg-muted/50">
|
||||||
<Loader2 className="size-4 animate-spin" />
|
<Loader2 className="size-4 animate-spin" />
|
||||||
Generating key for {agent.name}…
|
Generating key for {agent.name}…
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = `portabase agent "${agent.name}" --key ${data}`;
|
const command = `portabase agent "${agent.name}" --key ${agent.edgeKey}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 p-4 rounded-lg border border-border">
|
<div className="flex flex-col gap-3 p-4 rounded-lg border border-border">
|
||||||
<p className="text-sm font-medium">{agent.name}</p>
|
<p className="text-sm font-medium">{agent.name}</p>
|
||||||
<CodeSnippet title="Installation Command" code={command} />
|
<CodeSnippet title="Installation Command" code={command} />
|
||||||
<CodeSnippet title="Agent Key (manual)" code={data ?? ""} />
|
<CodeSnippet title="Agent Key (manual)" code={agent.edgeKey} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export type OnboardingDefaultsData = {
|
|||||||
export type OnboardingAgent = {
|
export type OnboardingAgent = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
edgeKey?: string;
|
||||||
notifierId?: string;
|
notifierId?: string;
|
||||||
storageId?: string;
|
storageId?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user