mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
fix: access control indexing type (#8155)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import type { LiteralString } from "@better-auth/core";
|
||||
import type { AuthorizeResponse, createAccessControl } from "./access";
|
||||
|
||||
export type ArrayElement<T> = T extends readonly (infer E)[] ? E : never;
|
||||
|
||||
export type SubArray<T extends unknown[] | readonly unknown[] | any[]> =
|
||||
| T[number][]
|
||||
| ReadonlyArray<T[number]>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BetterAuthClientPlugin } from "@better-auth/core";
|
||||
import type { AccessControl, Role } from "../access";
|
||||
import type { AccessControl, ArrayElement, Role } from "../access";
|
||||
import type { defaultStatements } from "./access";
|
||||
import { adminAc, userAc } from "./access";
|
||||
import type { admin } from "./admin";
|
||||
@@ -26,7 +26,7 @@ export const adminClient = <O extends AdminClientOptions>(
|
||||
type PermissionType = {
|
||||
[key in keyof Statements]?: Array<
|
||||
Statements[key] extends readonly unknown[]
|
||||
? Statements[key][number]
|
||||
? ArrayElement<Statements[key]>
|
||||
: never
|
||||
>;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "../../cookies";
|
||||
import { parseSessionOutput, parseUserOutput } from "../../db/schema";
|
||||
import { getDate } from "../../utils/date";
|
||||
import type { AccessControl } from "../access";
|
||||
import type { AccessControl, ArrayElement } from "../access";
|
||||
import type { defaultStatements } from "./access";
|
||||
import { ADMIN_ERROR_CODES } from "./error-codes";
|
||||
import { hasPermission } from "./has-permission";
|
||||
@@ -1603,7 +1603,7 @@ export const userHasPermission = <O extends AdminOptions>(opts: O) => {
|
||||
type PermissionType = {
|
||||
[key in keyof Statements]?: Array<
|
||||
Statements[key] extends readonly unknown[]
|
||||
? Statements[key][number]
|
||||
? ArrayElement<Statements[key]>
|
||||
: never
|
||||
>;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
} from "../../plugins/organization/schema";
|
||||
import type { BetterAuthOptions, BetterAuthPlugin } from "../../types";
|
||||
import type { Prettify } from "../../types/helper";
|
||||
import type { AccessControl, Role } from "../access";
|
||||
import type { AccessControl, ArrayElement, Role } from "../access";
|
||||
import type { defaultStatements } from "./access";
|
||||
import { adminAc, defaultRoles, memberAc, ownerAc } from "./access";
|
||||
import { ORGANIZATION_ERROR_CODES } from "./error-codes";
|
||||
@@ -95,7 +95,7 @@ export const organizationClient = <CO extends OrganizationClientOptions>(
|
||||
type PermissionType = {
|
||||
[key in keyof Statements]?: Array<
|
||||
Statements[key] extends readonly unknown[]
|
||||
? Statements[key][number]
|
||||
? ArrayElement<Statements[key]>
|
||||
: never
|
||||
>;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { APIError } from "@better-auth/core/error";
|
||||
import * as z from "zod";
|
||||
import { getSessionFromCtx } from "../../api";
|
||||
import { shimContext } from "../../utils/shim";
|
||||
import type { AccessControl } from "../access";
|
||||
import type { AccessControl, ArrayElement } from "../access";
|
||||
import type { defaultStatements } from "./access";
|
||||
import { defaultRoles } from "./access";
|
||||
import { getOrgAdapter } from "./adapter";
|
||||
@@ -183,7 +183,7 @@ const createHasPermission = <O extends OrganizationOptions>(options: O) => {
|
||||
type PermissionType = {
|
||||
[key in keyof Statements]?: Array<
|
||||
Statements[key] extends readonly unknown[]
|
||||
? Statements[key][number]
|
||||
? ArrayElement<Statements[key]>
|
||||
: never
|
||||
>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user