This project provides a simple authentication system implemented in Go (Golang), utilizing various libraries and technologies such as Fiber, GORM, CORS, MySQL, bcrypt, and JWT-Go.
- User registration
- User login
- User logout
- Retrieving a list of users
Fiber: A web framework for Go, known for its performance and ease of use.
GORM: An ORM library for Go, used for interacting with the MySQL database.
CORS: Cross-Origin Resource Sharing middleware to allow secure cross-origin requests.
MySQL: A popular relational database management system used for storing user data.
bcrypt: A library for hashing passwords securely.
JWT-Go: A JSON Web Token implementation for Go, used for authentication purposes.
1. Clone the repository:
git clone https://github.com/ppadti/JWT-Authentication.git
cd JWT-Authentication
2. Install dependencies:
go mod tidy
Set up the MySQL database. Make sure to update the database configuration in database/connection.go
3. Run the project:
go run main.go
POST /api/register
: Register a new user. Requires a JSON body with username, email and password fields.
POST /api/login
: Login with username and password. Returns a JWT token upon successful authentication.
POST /api/logout
: Logout the user. Requires a valid JWT token.
GET /api/users
: Retrieve a list of users. Requires a valid JWT token.