LeMonsalve
LeMonsalve
Explore posts from servers
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
We need to wait at least for v1.2.4
21 replies
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
Yesss
21 replies
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
@Bo3o Bro I was trying different things, admin api only works if your role are in adminRoles prop, even if you have granted permissions to list users, delete etc... So, you can add your role as admin and only grant unique permissions required to perform your required admin action
21 replies
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
I have my custom roles with custom permission set:
export const adminRole = accessControl.newRole({
...adminAc.statements,
});

export const sellerRole = accessControl.newRole({
user: ["list"],
session: [],
});

export const stockManagerRole = accessControl.newRole({
user: [],
session: [],
});
export const adminRole = accessControl.newRole({
...adminAc.statements,
});

export const sellerRole = accessControl.newRole({
user: ["list"],
session: [],
});

export const stockManagerRole = accessControl.newRole({
user: [],
session: [],
});
21 replies
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
I check the code and its true, the auth.ap.userHasPermission, returns correct value, but api resquests such listUsers({ headers: await headers() }) returns UNAUTHORIZED:
const res = await auth.api.userHasPermission({
headers: await headers(),
body: {
userId: session.user.id,
permission: {
user: ["list"],
},
},
});

console.log("User " + session.user.name + " with role " + session.user.role);
if (res.success) {
console.log("has permission");
} else {
console.log("has't permission");
}
console.log(res);

const resData = await auth.api.listUsers({
headers: await headers(),
query: {},
});

console.log(resData.users);
const res = await auth.api.userHasPermission({
headers: await headers(),
body: {
userId: session.user.id,
permission: {
user: ["list"],
},
},
});

console.log("User " + session.user.name + " with role " + session.user.role);
if (res.success) {
console.log("has permission");
} else {
console.log("has't permission");
}
console.log(res);

const resData = await auth.api.listUsers({
headers: await headers(),
query: {},
});

console.log(resData.users);
// User Tilin with role seller
// has permission
{ error: null, success: true }
⨯ [Error [APIError]: ] {
status: 'UNAUTHORIZED',
body: undefined,
headers: {},
statusCode: 401,
digest: '5381'
}
GET / 500 in 279ms
GET /favicon.ico 200 in 32ms
// User Tilin with role seller
// has permission
{ error: null, success: true }
⨯ [Error [APIError]: ] {
status: 'UNAUTHORIZED',
body: undefined,
headers: {},
statusCode: 401,
digest: '5381'
}
GET / 500 in 279ms
GET /favicon.ico 200 in 32ms
21 replies
BABetter Auth
Created by Bo3o on 3/10/2025 in #help
Unable to add impersonate permission to a new role
Hello, may be your access control config has mistakes
// permissions.ts
import { createAccessControl } from "better-auth/plugins/access";
import { defaultStatements, adminAc } from "better-auth/plugins/admin/access";

const statement = {
...defaultStatements,
} as const;

export const accessControl = createAccessControl(statement);

export const adminRole = accessControl.newRole({
...adminAc.statements,
});

export const managerRole = accessControl.newRole({
user: ["impersonate"],
session: [],
});
// permissions.ts
import { createAccessControl } from "better-auth/plugins/access";
import { defaultStatements, adminAc } from "better-auth/plugins/admin/access";

const statement = {
...defaultStatements,
} as const;

export const accessControl = createAccessControl(statement);

export const adminRole = accessControl.newRole({
...adminAc.statements,
});

export const managerRole = accessControl.newRole({
user: ["impersonate"],
session: [],
});
// auth.ts
import {
accessControl,
adminRole,
managerRole,
} from "./permissions";

export const auth = betterAuth({
// your code
plugins: [
admin({
impersonationSessionDuration: 60 * 60 * 24,
ac: accessControl,
roles: {
'admin': adminRole,
'manager': managerRole,
},
}),
],
});
// auth.ts
import {
accessControl,
adminRole,
managerRole,
} from "./permissions";

export const auth = betterAuth({
// your code
plugins: [
admin({
impersonationSessionDuration: 60 * 60 * 24,
ac: accessControl,
roles: {
'admin': adminRole,
'manager': managerRole,
},
}),
],
});
21 replies
BABetter Auth
Created by LeMonsalve on 3/7/2025 in #help
authClient generates error
package.json:
"dependencies": {
"@better-fetch/fetch": "^1.1.15",
"@hookform/resolvers": "^4.1.3",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.1.4",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-dropdown-menu": "^2.1.6",
"@radix-ui/react-label": "^2.1.2",
"@radix-ui/react-select": "^2.1.6",
"@radix-ui/react-separator": "^1.1.2",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-switch": "^1.1.3",
"@radix-ui/react-tabs": "^1.1.3",
"@radix-ui/react-toggle": "^1.1.2",
"@radix-ui/react-tooltip": "^1.1.8",
"@tanstack/react-query": "^5.67.2",
"axios": "^1.8.1",
"better-auth": "^1.2.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.40.0",
"hono": "^4.7.4",
"lucide-react": "^0.479.0",
"next": "15.2.1",
"next-themes": "^0.4.4",
"pg": "^8.13.3",
"postgres": "^3.4.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
"server-only": "^0.0.1",
"sonner": "^2.0.1",
"tailwind-merge": "^3.0.2",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.24.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/pg": "^8.11.11",
"@types/react": "^19",
"@types/react-dom": "^19",
"drizzle-kit": "^0.30.5",
"eslint": "^9",
"eslint-config-next": "15.2.1",
"tailwindcss": "^4",
"tsx": "^4.19.3",
"typescript": "^5"
},
"dependencies": {
"@better-fetch/fetch": "^1.1.15",
"@hookform/resolvers": "^4.1.3",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.1.4",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-dropdown-menu": "^2.1.6",
"@radix-ui/react-label": "^2.1.2",
"@radix-ui/react-select": "^2.1.6",
"@radix-ui/react-separator": "^1.1.2",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-switch": "^1.1.3",
"@radix-ui/react-tabs": "^1.1.3",
"@radix-ui/react-toggle": "^1.1.2",
"@radix-ui/react-tooltip": "^1.1.8",
"@tanstack/react-query": "^5.67.2",
"axios": "^1.8.1",
"better-auth": "^1.2.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.40.0",
"hono": "^4.7.4",
"lucide-react": "^0.479.0",
"next": "15.2.1",
"next-themes": "^0.4.4",
"pg": "^8.13.3",
"postgres": "^3.4.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
"server-only": "^0.0.1",
"sonner": "^2.0.1",
"tailwind-merge": "^3.0.2",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.24.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/pg": "^8.11.11",
"@types/react": "^19",
"@types/react-dom": "^19",
"drizzle-kit": "^0.30.5",
"eslint": "^9",
"eslint-config-next": "15.2.1",
"tailwindcss": "^4",
"tsx": "^4.19.3",
"typescript": "^5"
},
3 replies
CC#
Created by LeMonsalve on 4/12/2023 in #help
❔ Error passing builder.Configuration as argument - .net 7
Hey, help me please!
3 replies