mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-17 21:37:06 -04:00
* feat: oidc feat: organization switcher refactor: org context feat: invitations GLM * feat: link current account * refactor: own page for sso registration * feat: per-user account management * refactor: code style * refactor: user existing check * refactor: restrict provider configuration to super admins only * refactor: cleanup / pr review * chore: fix lint issues * chore: pr feedbacks * test(e2e): automated tests for OIDC * fix: check url first for sso provider identification * fix: prevent oidc provider to be named "credential"
32 lines
881 B
TypeScript
32 lines
881 B
TypeScript
import { createServerFn } from "@tanstack/react-start";
|
|
import { auth } from "../auth";
|
|
import { getRequest } from "@tanstack/react-start/server";
|
|
|
|
export const getOrganizationContext = createServerFn({ method: "GET" }).handler(async () => {
|
|
const request = getRequest();
|
|
|
|
const [data, session] = await Promise.all([
|
|
auth.api.listOrganizations({
|
|
headers: request.headers,
|
|
}),
|
|
auth.api.getSession({ headers: request.headers }),
|
|
]);
|
|
|
|
const activeOrganizationId = session?.session?.activeOrganizationId;
|
|
const activeOrganization = data.find((org) => org.id === activeOrganizationId);
|
|
|
|
if (data.length === 0) {
|
|
throw new Error("No organizations found for user");
|
|
}
|
|
|
|
const member = await auth.api.getActiveMember({
|
|
headers: request.headers,
|
|
});
|
|
|
|
return {
|
|
organizations: data,
|
|
activeOrganization: activeOrganization || data[0],
|
|
activeMember: member,
|
|
};
|
|
});
|