mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
fix(organization): Certain parameters not showing in client types (#5214)
This commit is contained in:
@@ -292,12 +292,12 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
.and(
|
||||
z.union([
|
||||
z.object({
|
||||
roleName: z.string().meta({
|
||||
roleName: z.string().nonempty().meta({
|
||||
description: "The name of the role to delete",
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
roleId: z.string().meta({
|
||||
roleId: z.string().nonempty().meta({
|
||||
description: "The id of the role to delete",
|
||||
}),
|
||||
}),
|
||||
@@ -307,14 +307,11 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
use: [orgSessionMiddleware],
|
||||
metadata: {
|
||||
$Infer: {
|
||||
body: {} as (
|
||||
| {
|
||||
roleName: string;
|
||||
}
|
||||
| {
|
||||
roleId: string;
|
||||
}
|
||||
) & { organizationId?: string | undefined },
|
||||
body: {} as {
|
||||
roleName?: string | undefined;
|
||||
roleId?: string | undefined;
|
||||
organizationId?: string | undefined;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -392,7 +389,7 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
});
|
||||
}
|
||||
|
||||
if ("roleName" in ctx.body) {
|
||||
if (ctx.body.roleName) {
|
||||
const roleName = ctx.body.roleName;
|
||||
const defaultRoles = options.roles
|
||||
? Object.keys(options.roles)
|
||||
@@ -413,20 +410,29 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
}
|
||||
|
||||
let condition: Where;
|
||||
if ("roleName" in ctx.body) {
|
||||
if (ctx.body.roleName) {
|
||||
condition = {
|
||||
field: "role",
|
||||
value: ctx.body.roleName,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
} else if (ctx.body.roleId) {
|
||||
condition = {
|
||||
field: "id",
|
||||
value: ctx.body.roleId,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
// shouldn't be able to reach here given the schema validation.
|
||||
// But just in case, throw an error.
|
||||
ctx.context.logger.error(
|
||||
`[Dynamic Access Control] The role name/id is not provided in the request body.`,
|
||||
);
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
const existingRoleInDB =
|
||||
await ctx.context.adapter.findOne<OrganizationRole>({
|
||||
@@ -619,12 +625,12 @@ export const getOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
.and(
|
||||
z.union([
|
||||
z.object({
|
||||
roleName: z.string().meta({
|
||||
roleName: z.string().nonempty().meta({
|
||||
description: "The name of the role to read",
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
roleId: z.string().meta({
|
||||
roleId: z.string().nonempty().meta({
|
||||
description: "The id of the role to read",
|
||||
}),
|
||||
}),
|
||||
@@ -635,7 +641,9 @@ export const getOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
$Infer: {
|
||||
query: {} as {
|
||||
organizationId?: string | undefined;
|
||||
} & ({ roleName: string } | { roleId: string }),
|
||||
roleName?: string | undefined;
|
||||
roleId?: string | undefined;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -710,20 +718,29 @@ export const getOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
}
|
||||
|
||||
let condition: Where;
|
||||
if ("roleName" in ctx.query) {
|
||||
if (ctx.query.roleName) {
|
||||
condition = {
|
||||
field: "role",
|
||||
value: ctx.query.roleName,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
} else if (ctx.query.roleId) {
|
||||
condition = {
|
||||
field: "id",
|
||||
value: ctx.query.roleId,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
// shouldn't be able to reach here given the schema validation.
|
||||
// But just in case, throw an error.
|
||||
ctx.context.logger.error(
|
||||
`[Dynamic Access Control] The role name/id is not provided in the request query.`,
|
||||
);
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
let role = await ctx.context.adapter.findOne<OrganizationRole>({
|
||||
model: "organizationRole",
|
||||
@@ -791,12 +808,12 @@ export const updateOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
.and(
|
||||
z.union([
|
||||
z.object({
|
||||
roleName: z.string().meta({
|
||||
roleName: z.string().nonempty().meta({
|
||||
description: "The name of the role to update",
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
roleId: z.string().meta({
|
||||
roleId: z.string().nonempty().meta({
|
||||
description: "The id of the role to update",
|
||||
}),
|
||||
}),
|
||||
@@ -810,7 +827,9 @@ export const updateOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
permission?: Record<string, string[]> | undefined;
|
||||
roleName?: string | undefined;
|
||||
} & AdditionalFields;
|
||||
} & ({ roleName: string } | { roleId: string }),
|
||||
roleName?: string | undefined;
|
||||
roleId?: string | undefined;
|
||||
},
|
||||
},
|
||||
},
|
||||
use: [orgSessionMiddleware],
|
||||
@@ -893,20 +912,29 @@ export const updateOrgRole = <O extends OrganizationOptions>(options: O) => {
|
||||
}
|
||||
|
||||
let condition: Where;
|
||||
if ("roleName" in ctx.body) {
|
||||
if (ctx.body.roleName) {
|
||||
condition = {
|
||||
field: "role",
|
||||
value: ctx.body.roleName,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
} else if (ctx.body.roleId) {
|
||||
condition = {
|
||||
field: "id",
|
||||
value: ctx.body.roleId,
|
||||
operator: "eq",
|
||||
connector: "AND",
|
||||
};
|
||||
} else {
|
||||
// shouldn't be able to reach here given the schema validation.
|
||||
// But just in case, throw an error.
|
||||
ctx.context.logger.error(
|
||||
`[Dynamic Access Control] The role name/id is not provided in the request body.`,
|
||||
);
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
let role = await ctx.context.adapter.findOne<OrganizationRole>({
|
||||
model: "organizationRole",
|
||||
|
||||
Reference in New Issue
Block a user