Authentication
DW uses Better-Auth for authentication and authorization. Middleware, login/registration flows, and RBAC utilities are pre-configured.
Configuration
Auth roles are defined in src/config/auth.ts. Modify this file to add or change roles.
Adding a New Collection
When adding a new database collection that needs auth:
- Create the migration
- Update the schema in
src/config/schema.ts - Add auth roles in
src/config/auth.ts - Configure ownership rules
RBAC Patterns
Simple Ownership
User owns their own content directly:
{ collection: 'posts', ownership: 'direct', field: 'user_id'}Complex Ownership
Content owned through relationships (teams, organizations):
{ collection: 'team_posts', ownership: 'relationship', // Custom ownership check logic}OAuth Setup
For social login providers, you’ll need to:
- Create an app in the provider’s developer console
- Get client ID and secret
- Add credentials to
.env - Configure the provider in Better-Auth
2FA
Two-factor authentication is available via Better-Auth. Requires additional forms and flows - see the Better-Auth documentation.