mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 16:36:51 +00:00
Corrigiu acesso admin após login
X-Lovable-Edit-ID: edt-f9ce9af8-9c43-4ba3-bb04-9cfc756f0296 Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
commit
cb18639085
1 changed files with 36 additions and 14 deletions
|
|
@ -100,15 +100,36 @@ function AgentDetailPage() {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from("agent_instances")
|
.from("agent_instances")
|
||||||
.select(
|
.select(
|
||||||
`id, user_id, uuid_tenant, status, telegram_bot_username, telegram_user_chat_id,
|
"id, user_id, uuid_tenant, status, telegram_bot_username, telegram_user_chat_id, railway_service_id, vps_pool_id, provisioned_at, created_at, model_config",
|
||||||
railway_service_id, vps_pool_id, provisioned_at, created_at, model_config,
|
|
||||||
vps_pool:vps_pool_id(railway_project_id, railway_environment_id),
|
|
||||||
profile:profiles!agent_instances_user_id_fkey(full_name, phone, onboarding_completed)`,
|
|
||||||
)
|
)
|
||||||
.eq("id", id)
|
.eq("id", id)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
if (error) throw error;
|
if (error) {
|
||||||
if (!data) return null;
|
console.error("[admin.agente] agent query error", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
console.warn("[admin.agente] agent not found", { id });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buscar profile separadamente (evita join com possíveis problemas de FK)
|
||||||
|
const { data: profileData } = await supabase
|
||||||
|
.from("profiles")
|
||||||
|
.select("full_name, phone, onboarding_completed")
|
||||||
|
.eq("id", data.user_id)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
// Buscar vps_pool separadamente se houver
|
||||||
|
let vpsPool: { railway_project_id: string | null; railway_environment_id: string | null } | null = null;
|
||||||
|
if (data.vps_pool_id) {
|
||||||
|
const { data: poolData } = await supabase
|
||||||
|
.from("vps_pool")
|
||||||
|
.select("railway_project_id, railway_environment_id")
|
||||||
|
.eq("id", data.vps_pool_id)
|
||||||
|
.maybeSingle();
|
||||||
|
vpsPool = poolData ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
const { data: subscriptionData, error: subscriptionError } = await supabase
|
const { data: subscriptionData, error: subscriptionError } = await supabase
|
||||||
.from("subscriptions")
|
.from("subscriptions")
|
||||||
|
|
@ -119,10 +140,6 @@ function AgentDetailPage() {
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
if (subscriptionError) throw subscriptionError;
|
if (subscriptionError) throw subscriptionError;
|
||||||
|
|
||||||
// Normalizar arrays vindos do PostgREST
|
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
const d = data as any;
|
|
||||||
const profile = Array.isArray(d.profile) ? d.profile[0] ?? null : d.profile;
|
|
||||||
const subscription = subscriptionData
|
const subscription = subscriptionData
|
||||||
? {
|
? {
|
||||||
...subscriptionData,
|
...subscriptionData,
|
||||||
|
|
@ -132,10 +149,15 @@ function AgentDetailPage() {
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// Email não é acessível via client (RLS) — admin pode ver no Railway/Telegram
|
const result = {
|
||||||
const userEmail: string | null = null;
|
...data,
|
||||||
|
vps_pool: vpsPool,
|
||||||
return { ...d, profile, subscription, user_email: userEmail } as AgentDetail;
|
profile: profileData ?? null,
|
||||||
|
subscription,
|
||||||
|
user_email: null as string | null,
|
||||||
|
} as AgentDetail;
|
||||||
|
console.log("[admin.agente] agent loaded", { id: result.id, status: result.status });
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue