feat: add real account workspace controls
This commit is contained in:
29
app/api/auth/organization/route.ts
Normal file
29
app/api/auth/organization/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { jsonFailure, jsonSuccess, readJsonBody } from "@/modules/core/server/api";
|
||||
import { switchActiveOrganization } from "@/modules/core/server/auth";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export async function POST(request: Request): Promise<Response> {
|
||||
const body = await readJsonBody(request);
|
||||
if (!isRecord(body) || typeof body.organizationId !== "string" || !body.organizationId.trim()) {
|
||||
return jsonFailure("机构不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
const context = await switchActiveOrganization(body.organizationId.trim());
|
||||
|
||||
return jsonSuccess("机构已切换", {
|
||||
account: context.account,
|
||||
organization: context.organization ?? null,
|
||||
organizations: context.organizations,
|
||||
membership: context.membership ?? null,
|
||||
permissions: context.permissions,
|
||||
});
|
||||
} catch (error) {
|
||||
return jsonFailure(error instanceof Error ? error.message : "机构切换失败", 403);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export async function GET(): Promise<Response> {
|
||||
return jsonSuccess("Session loaded", {
|
||||
account: context?.account ?? null,
|
||||
organization: context?.organization ?? null,
|
||||
organizations: context?.organizations ?? [],
|
||||
membership: context?.membership ?? null,
|
||||
permissions: context?.permissions ?? [],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user