Overview
The Church Management System implements a role-based access control (RBAC) system with two primary roles: Pastor and Member. Each role has specific permissions that determine what actions users can perform within the system.User Roles
Pastor
Pastors have administrative privileges and can manage church operations, including:- Creating and managing churches
- Managing church members
- Creating and managing donation campaigns
- Viewing all church statistics and reports
- Inviting new members to the church
Member
Members have limited access focused on participation:- Viewing church information
- Participating in donation campaigns
- Viewing their own donation history
- Updating their own profile
The role is assigned during user registration and cannot be changed after account creation.
Authentication Schema
The authentication system stores user credentials and role information:See the full schema in
authprofilemodel.js:3-37Role Enforcement
Role-based access control is enforced through middleware that validates the user’s role before allowing access to protected routes.Authorization Middleware
The system uses theauthorizeRoles middleware to restrict access:
See implementation in
rolemidddleware.js:1-14Role-Based Endpoints
Pastor-Only Endpoints
Pastor-Only Endpoints
POST /api/churches- Create a new churchPUT /api/churches/:id- Update church informationDELETE /api/churches/:id- Delete a churchPOST /api/donations- Create donation campaignsPUT /api/donations/:id- Update donation campaignsDELETE /api/donations/:id- Delete donation campaignsPOST /api/churches/:id/members- Add members to churchDELETE /api/churches/:id/members/:memberId- Remove members
Member & Pastor Endpoints
Member & Pastor Endpoints
GET /api/churches- View churchesGET /api/churches/:id- View church detailsGET /api/donations- View donation campaignsGET /api/donations/:id- View donation detailsPOST /api/donations/:id/donate- Make a donationGET /api/profile- View own profilePUT /api/profile- Update own profile
Invitation System
The system tracks user invitations through theinvitedBy field:
Profile Completion
New users must complete their profile after registration:- The
isProfileCompleteflag tracks profile status - Defaults to
falseon registration - Set to
trueafter users provide required profile information - Incomplete profiles may have restricted access to certain features
Users with incomplete profiles should be prompted to complete their profile information before accessing full system features.
Best Practices
- Always validate roles on the backend - Never rely solely on client-side role checks
- Use the middleware - Apply
authorizeRolesmiddleware to all protected routes - Log authorization failures - Track failed authorization attempts for security auditing
- Handle 403 errors gracefully - Provide clear feedback when users lack permissions