Files
zerobyte/app/server/lib/functions/organization-context.ts
Nico 7a3932f969 feat: OIDC (#564)
* 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"
2026-02-27 23:13:54 +01:00

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,
};
});