mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 04:19:20 +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(
|
.and(
|
||||||
z.union([
|
z.union([
|
||||||
z.object({
|
z.object({
|
||||||
roleName: z.string().meta({
|
roleName: z.string().nonempty().meta({
|
||||||
description: "The name of the role to delete",
|
description: "The name of the role to delete",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
roleId: z.string().meta({
|
roleId: z.string().nonempty().meta({
|
||||||
description: "The id of the role to delete",
|
description: "The id of the role to delete",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -307,14 +307,11 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
use: [orgSessionMiddleware],
|
use: [orgSessionMiddleware],
|
||||||
metadata: {
|
metadata: {
|
||||||
$Infer: {
|
$Infer: {
|
||||||
body: {} as (
|
body: {} as {
|
||||||
| {
|
roleName?: string | undefined;
|
||||||
roleName: string;
|
roleId?: string | undefined;
|
||||||
}
|
organizationId?: string | undefined;
|
||||||
| {
|
},
|
||||||
roleId: string;
|
|
||||||
}
|
|
||||||
) & { 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 roleName = ctx.body.roleName;
|
||||||
const defaultRoles = options.roles
|
const defaultRoles = options.roles
|
||||||
? Object.keys(options.roles)
|
? Object.keys(options.roles)
|
||||||
@@ -413,20 +410,29 @@ export const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let condition: Where;
|
let condition: Where;
|
||||||
if ("roleName" in ctx.body) {
|
if (ctx.body.roleName) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "role",
|
field: "role",
|
||||||
value: ctx.body.roleName,
|
value: ctx.body.roleName,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
connector: "AND",
|
||||||
};
|
};
|
||||||
} else {
|
} else if (ctx.body.roleId) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "id",
|
field: "id",
|
||||||
value: ctx.body.roleId,
|
value: ctx.body.roleId,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
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 =
|
const existingRoleInDB =
|
||||||
await ctx.context.adapter.findOne<OrganizationRole>({
|
await ctx.context.adapter.findOne<OrganizationRole>({
|
||||||
@@ -619,12 +625,12 @@ export const getOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
.and(
|
.and(
|
||||||
z.union([
|
z.union([
|
||||||
z.object({
|
z.object({
|
||||||
roleName: z.string().meta({
|
roleName: z.string().nonempty().meta({
|
||||||
description: "The name of the role to read",
|
description: "The name of the role to read",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
roleId: z.string().meta({
|
roleId: z.string().nonempty().meta({
|
||||||
description: "The id of the role to read",
|
description: "The id of the role to read",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -635,7 +641,9 @@ export const getOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
$Infer: {
|
$Infer: {
|
||||||
query: {} as {
|
query: {} as {
|
||||||
organizationId?: string | undefined;
|
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;
|
let condition: Where;
|
||||||
if ("roleName" in ctx.query) {
|
if (ctx.query.roleName) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "role",
|
field: "role",
|
||||||
value: ctx.query.roleName,
|
value: ctx.query.roleName,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
connector: "AND",
|
||||||
};
|
};
|
||||||
} else {
|
} else if (ctx.query.roleId) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "id",
|
field: "id",
|
||||||
value: ctx.query.roleId,
|
value: ctx.query.roleId,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
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>({
|
let role = await ctx.context.adapter.findOne<OrganizationRole>({
|
||||||
model: "organizationRole",
|
model: "organizationRole",
|
||||||
@@ -791,12 +808,12 @@ export const updateOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
.and(
|
.and(
|
||||||
z.union([
|
z.union([
|
||||||
z.object({
|
z.object({
|
||||||
roleName: z.string().meta({
|
roleName: z.string().nonempty().meta({
|
||||||
description: "The name of the role to update",
|
description: "The name of the role to update",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
roleId: z.string().meta({
|
roleId: z.string().nonempty().meta({
|
||||||
description: "The id of the role to update",
|
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;
|
permission?: Record<string, string[]> | undefined;
|
||||||
roleName?: string | undefined;
|
roleName?: string | undefined;
|
||||||
} & AdditionalFields;
|
} & AdditionalFields;
|
||||||
} & ({ roleName: string } | { roleId: string }),
|
roleName?: string | undefined;
|
||||||
|
roleId?: string | undefined;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
use: [orgSessionMiddleware],
|
use: [orgSessionMiddleware],
|
||||||
@@ -893,20 +912,29 @@ export const updateOrgRole = <O extends OrganizationOptions>(options: O) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let condition: Where;
|
let condition: Where;
|
||||||
if ("roleName" in ctx.body) {
|
if (ctx.body.roleName) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "role",
|
field: "role",
|
||||||
value: ctx.body.roleName,
|
value: ctx.body.roleName,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
connector: "AND",
|
||||||
};
|
};
|
||||||
} else {
|
} else if (ctx.body.roleId) {
|
||||||
condition = {
|
condition = {
|
||||||
field: "id",
|
field: "id",
|
||||||
value: ctx.body.roleId,
|
value: ctx.body.roleId,
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
connector: "AND",
|
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>({
|
let role = await ctx.context.adapter.findOne<OrganizationRole>({
|
||||||
model: "organizationRole",
|
model: "organizationRole",
|
||||||
|
|||||||
Reference in New Issue
Block a user