repositorypackage
0.0.0-20250207002850-3fb65b17c431
Repository: https://github.com/erdembaran/go-auth.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
Go Authentication API
A robust authentication API built with Go, Fiber, and MongoDB that provides comprehensive user authentication functionality.
Features
- š User Authentication (Login/Logout/Register/Forgot password/Reset-password)
- š JWT-based Authentication
- š§ Password Reset via Email
- š¤ User Management
- š Secure Password Hashing
- šŖ HTTP-Only Cookie Support
- š MongoDB Integration
- š³ Docker Support
- š Production-Ready Deployment
Prerequisites
Before running this project, make sure you have the following installed:
- Go (1.22 or later)
- MongoDB
- Docker & Docker Compose (for containerized setup)
- SMTP Server (for email functionality)
Installation
Local Development
- Clone the repository
git clone https://github.com/erdembaran/go-auth.git
cd go-auth
- Install dependencies
go mod download
- Set up environment variables (create a
.env.local
file)
PORT=4000
MONGO_URI=mongodb://mongodb:27017/go-auth?directConnection=true
ENV=local
JWT_SECRET=your-jwt-secret
SMTP_HOST=smtp.example.com
SMTP_PORT=smtp_port
[email protected]
SMTP_PASS=your-email-password
Using Docker
- Make sure Docker and Docker Compose are installed
- Run the application using Docker Compose:
docker-compose up --build
The API will be available at http://localhost:4000
Production Deployment (Render)
For production deployment on Render:
- Create a new Web Service on Render
- Choose "Docker Registry" as deployment type
- Use the following Docker image:
baranerdem/go-auth:latest
- Set the following:
- Instance Type: Choose based on your needs (Free/Standard)
- Region: Choose closest to your users
- Branch: main
- Add the following environment variables in Render dashboard:
PORT=4000 MONGO_URI=your-mongodb-atlas-uri ENV=production JWT_SECRET=your-production-jwt-secret SMTP_HOST=your-smtp-host SMTP_PORT=your-smtp-port SMTP_USER=your-smtp-user SMTP_PASS=your-smtp-password
- Click "Create Web Service"
The service will automatically pull the Docker image and deploy your application.
API Endpoints
Authentication Routes
POST /api/v1/auth/register - Register a new user
POST /api/v1/auth/login - Login user
POST /api/v1/auth/logout - Logout user
POST /api/v1/auth/forgot-password - Request password reset
PUT /api/v1/auth/reset-password/:token - Reset password
User Routes (Protected)
GET /api/v1/users - Get all users
GET /api/v1/users/:id - Get specific user
Development
Running Locally with Air (Hot Reload)
air
Running with Docker
# Start the application and MongoDB
docker-compose up --build
# Stop the application
docker-compose down
# Remove volumes (if needed)
docker-compose down -v
Security Features
- Password Hashing using bcrypt
- JWT Authentication
- HTTP-Only Cookies
- Secure Password Reset Flow
- Protected Routes with Middleware
- Environment-based Configuration
- Secure Production Setup
Project Structure
.
āāā config/ # Configuration and environment setup
āāā controllers/ # Request handlers
āāā database/ # Database connection and models
āāā middleware/ # Custom middleware
āāā models/ # Data models
āāā routes/ # API routes
āāā utils/ # Utility functions
āāā .env.local # Local environment variables
āāā Dockerfile # Docker configuration
āāā docker-compose.yml # Docker Compose configuration
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Acknowledgments