curl --request GET \
--url https://api.example.com/api/organization/context{
"success": true,
"data": {
"id": "<string>",
"name": "<string>",
"slug": "<string>",
"isPlatformAdminView": true
},
"isPlatformAdmin": true,
"message": "<string>"
}Retrieve the active organization for the authenticated user
curl --request GET \
--url https://api.example.com/api/organization/context{
"success": true,
"data": {
"id": "<string>",
"name": "<string>",
"slug": "<string>",
"isPlatformAdminView": true
},
"isPlatformAdmin": true,
"message": "<string>"
}GET /api/organization/context
orgId parameter is reserved for future multi-tenant features. Currently, it’s ignored and the user’s assigned organization is always returned.curl -X GET https://your-domain.com/api/organization/context \
-H "Cookie: your-session-cookie"
{
"success": true,
"data": {
"id": "org-uuid-123",
"name": "La Tasca Group",
"slug": "la-tasca-group",
"isPlatformAdminView": false
},
"isPlatformAdmin": false
}
{
"success": true,
"data": null,
"isPlatformAdmin": false,
"message": "No hay organización activa"
}
{
"success": false,
"error": "Error al obtener contexto de organización"
}
getActiveOrganization() helper:
import { getActiveOrganization } from "@/lib/organization-context";
export async function GET(request: NextRequest) {
try {
const activeOrg = await getActiveOrganization();
if (!activeOrg) {
return NextResponse.json({
success: true,
data: null,
isPlatformAdmin: false,
message: "No hay organización activa"
});
}
return NextResponse.json({
success: true,
data: activeOrg,
isPlatformAdmin: activeOrg.isPlatformAdminView
});
} catch (error: any) {
logger.error("Error getting organization context", "OrganizationAPI", error);
return NextResponse.json(
{ success: false, error: error.message },
{ status: 500 }
);
}
}
getActiveOrganization() function:
organization_idorganizations tableconst isPlatformAdmin = role === 'super_admin';
super_admin role = Platform adminorgId query parameter is ignoredisPlatformAdminView is always falsegetActiveOrganization() to support organization switching via localStorage or query parameters.const response = await fetch('/api/organization/context');
const { success, data } = await response.json();
if (success && data) {
console.log(`Active organization: ${data.name}`);
// Store in context/state management
} else {
// Redirect to organization setup
}
logger.error("Error getting organization context", "OrganizationAPI", error);