stepman
stepman
BABetter Auth
Created by Mehr on 2/28/2025 in #help
How client plugins actions can be accessed?
My understanding is that where the function is exposed is controlled by the map you return in getActions. Here's a snippet from one of my plugins:
export const organizationAdminClientPlugin = () => {
return {
id: "org-admin",
$InferServerPlugin: {} as ReturnType<OrganizationAdminPlugin>,
getActions(/* $fetch */) {
return {
test: {
foo: () => { return "bar" };
admin: {
getRoleLabel: (s: string) => {
// TODO: fix role lookup
return `${s}:label`;
},
},
};
},
} satisfies BetterAuthClientPlugin;
};
export const organizationAdminClientPlugin = () => {
return {
id: "org-admin",
$InferServerPlugin: {} as ReturnType<OrganizationAdminPlugin>,
getActions(/* $fetch */) {
return {
test: {
foo: () => { return "bar" };
admin: {
getRoleLabel: (s: string) => {
// TODO: fix role lookup
return `${s}:label`;
},
},
};
},
} satisfies BetterAuthClientPlugin;
};
This will expose two functions, authClient.test.foo() and authClient.admin.getRoleLabel().
4 replies
BABetter Auth
Created by je823 on 5/19/2025 in #help
listOrganizations params - docs are no help
I had the same issue, and as far as I could tell the existing functionality was restricted to the current user's orgs only. So I built my own "Org Admin" plugin:
export const organizationAdminPlugin = () => {
return {
id: "org-admin",
endpoints: {
listAllOrganizations: createAuthEndpoint(
"/organization/admin/listall",
{
method: "GET",
},
async (ctx) => {
const orgs = ctx.context.adapter.findMany<Organization>({
model: "organization",
});
return ctx.json(orgs);
},
),
/* ... */
export const organizationAdminPlugin = () => {
return {
id: "org-admin",
endpoints: {
listAllOrganizations: createAuthEndpoint(
"/organization/admin/listall",
{
method: "GET",
},
async (ctx) => {
const orgs = ctx.context.adapter.findMany<Organization>({
model: "organization",
});
return ctx.json(orgs);
},
),
/* ... */
4 replies