Authentication service for the Hourglass application with Google OAuth integration and intelligent image processing.
- 🔐 Google OAuth 2.0 authentication
- 🖼️ Automatic image processing with Cloudinary
- 🎨 Fallback avatar generation with user initials
- 📱 Responsive profile picture handling
- 🔒 Secure session management
- Automatically uploads Google profile pictures to Cloudinary
- Optimizes images (200x200px, auto quality)
- Organized in folders for better management
- Generates beautiful initial-based avatars when no profile picture exists
- Uses Canvas to create circular avatars with user's first initial
- Consistent color scheme based on user's name
- Uploads generated avatars to Cloudinary
- Multiple fallback levels ensure users always have a profile picture
- Graceful degradation to external avatar service if all else fails
- Clone the repository
git clone <repository-url>
cd hourglass-auth- Install dependencies
npm install- Configure environment variables
Copy
.env.exampleto.envand fill in your credentials:
cp .env.example .envRequired environment variables:
GOOGLE_CLIENT_ID- Google OAuth client IDGOOGLE_CLIENT_SECRET- Google OAuth client secretGOOGLE_CALLBACK_URL- OAuth callback URLCLOUDINARY_CLOUD_NAME- Cloudinary cloud nameCLOUDINARY_API_KEY- Cloudinary API keyCLOUDINARY_API_SECRET- Cloudinary API secretDATABASE_URL- PostgreSQL database URLSESSION_SECRET- Session encryption secret
- Run the application
npm run devGET /auth/google- Initiate Google OAuthGET /auth/google/callback- OAuth callbackGET /auth/logout- Logout userGET /api/user- Get current user infoGET /health- Health check
src/
├── app.js # Express app configuration
├── index.js # Application entry point
├── passport.js # Passport OAuth configuration
├── controllers/ # Route controllers
├── database/ # Database configuration
├── routes/ # API routes
└── utils/ # Utility functions
├── imageHandler.js # Image processing utilities
└── testImageProcessing.js # Testing utilities
- User Authentication: When a user logs in with Google
- Image Check: System checks if user has a Google profile picture
- Upload to Cloudinary: If image exists, uploads to Cloudinary with optimization
- Generate Fallback: If no image, generates a beautiful initial-based avatar
- Store URL: Saves the final image URL to the database
- Error Handling: Falls back to external service if Cloudinary fails
For development mode with auto-reload:
npm run devFor production:
npm startISC