role-based authorization
Hi, I'm implementing role-based access control in my admin panel and facing a challenge. I need to restrict access so only users with
user.metadata.role === "ADMIN"
can log in.
What's the recommended approach in Better Auth to:
- Validate a user's role/permissions BEFORE creating a session?
- Is there any equivalent to Next Auth's authorize callback that lets me check custom conditions during login?Solution:Jump to solution
thanks @Soheel i tried with
hooks
(not databasehooks
), it worked 🎉
I added this to my auth
config
```ts
hooks: {...3 Replies
I'd assum the hooks https://www.better-auth.com/docs/reference/options#hooks are what suit you best here
Options | Better Auth
Better Auth configuration options reference.
Maybe dataBase hooks actually: https://www.better-auth.com/docs/reference/options#databasehooks
Options | Better Auth
Better Auth configuration options reference.
Solution
thanks @Soheel i tried with
hooks
(not databasehooks
), it worked 🎉
I added this to my auth
config