mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 12:36:50 +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
|
||||
.from("agent_instances")
|
||||
.select(
|
||||
`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,
|
||||
vps_pool:vps_pool_id(railway_project_id, railway_environment_id),
|
||||
profile:profiles!agent_instances_user_id_fkey(full_name, phone, onboarding_completed)`,
|
||||
"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",
|
||||
)
|
||||
.eq("id", id)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
if (!data) return null;
|
||||
if (error) {
|
||||
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
|
||||
.from("subscriptions")
|
||||
|
|
@ -119,10 +140,6 @@ function AgentDetailPage() {
|
|||
.maybeSingle();
|
||||
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
|
||||
? {
|
||||
...subscriptionData,
|
||||
|
|
@ -132,10 +149,15 @@ function AgentDetailPage() {
|
|||
}
|
||||
: null;
|
||||
|
||||
// Email não é acessível via client (RLS) — admin pode ver no Railway/Telegram
|
||||
const userEmail: string | null = null;
|
||||
|
||||
return { ...d, profile, subscription, user_email: userEmail } as AgentDetail;
|
||||
const result = {
|
||||
...data,
|
||||
vps_pool: vpsPool,
|
||||
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