This project is a simple Golang application that showcases best practices for user and admin authentication using JSON Web Tokens (JWT).
- User and admin authentication using JSON Web Tokens (JWT).
- Secure user registration with password hashing.
- Authorization middleware to protect routes.
- Role-based access control (user and admin roles).
- Flexible configuration options.
Before you begin, ensure you have the following installed on your system:
- Go
- MongoDB or another preferred database system.
Clone the repository:
git clone https://github.com/your-username/your-golang-jwt-project.git
cd your-golang-jwt-project
go mod tidy
go run main.go
- Obtain an authentication token by sending a POST request to
/auth
with valid credentials (username and password). - Include the obtained JWT token in the Authorization header for protected routes.
- Register a new user by sending a POST request to
/register
with user details. - New users will be assigned the "user" role by default.
- To access admin-only routes, a user must have the "admin" role.
- Admins can be assigned manually through the database or using an admin endpoint (if implemented).
You can configure the project by modifying the .env
file or using environment variables. Refer to CONFIGURATION.md
for detailed configuration options.
We welcome contributions from the community. To contribute to this project, please follow our Contributing Guidelines.
This project is licensed under the MIT License. See LICENSE.md
for details.