feature:Authentication#3
Merged
Christopherdominic merged 2 commits intoChristopherdominic:mainfrom Mar 5, 2026
Merged
Conversation
3592e8e to
a043c08
Compare
Emmyt24
pushed a commit
to Emmyt24/course_flow-backend
that referenced
this pull request
Mar 11, 2026
…ation feature:Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Authentication System Documentation
Overview
This School API implements a comprehensive role-based authentication system with support for three user roles:
Architecture
Layered Design
Key Components
Models (
src/models/user.rs)Services (
src/services/auth_services.rs)Controllers (
src/controllers/Auth_controllers.rs)Utils (
src/utils/)API Endpoints
Admin Authentication
Register Admin
Login Admin
Student Authentication
Register Student
Login Student
Mentor Authentication
Register Mentor
Login Mentor
Common Endpoints
Refresh Access Token
Get Current User Profile
Verify Token
Logout
Security Features
Password Security
JWT Tokens
Role-Based Access Control
Database Security
Error Handling
All errors return appropriate HTTP status codes:
Configuration
Environment Variables
Create a
.envfile in the project root:Database Schema
The
userstable structure:Indexes:
idx_users_email- Fast email lookupsidx_users_role- Filter by roleidx_users_is_active- Filter active usersUsage Examples
Register a New Admin
Login as Student
Get Current User (with token)
curl -X GET http://localhost:3000/auth/me \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"Refresh Token
Middleware Integration
The authentication middleware is available in
src/middlewares/auth_middleware.rs:auth_middleware- Extracts and validates JWT tokensrole_middleware- Validates user has required roleThese can be applied to protected routes to enforce authentication and authorization.
Best Practices
Future Enhancements