A comprehensive NestJS API for market data and news aggregation with Google OAuth authentication, built for the Australian market.
- Google OAuth Authentication - Secure user login with Google accounts
- Market Data Integration - Real-time market data from multiple sources
- News Aggregation - Australian financial news from AFR, ASX, and RBA
- JWT Token Management - Secure session management
- Rate Limiting - API protection and throttling
- Caching - Performance optimization
- Swagger Documentation - Interactive API documentation
- Node.js 20.18.1+ (use
nvm useto switch to the correct version) - npm or yarn
- Google Cloud Console account (for OAuth)
- Cloudflare Tunnel (for local development)
# Clone the repository
git clone <your-repo-url>
cd market-sum
# Switch to the correct Node.js version
nvm use
# Install dependencies
npm install
# or
yarn installCreate a .env file in the project root:
cp env.example .envUpdate the .env file with your configuration:
# Application Configuration
NODE_ENV=development
PORT=3000
API_PREFIX=api/v1
# Google OAuth Configuration (you'll get these in step 3)
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GOOGLE_CALLBACK_URL=https://your-ngrok-url.ngrok.io/api/v1/auth/google/callback
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_change_in_production
JWT_EXPIRES_IN=7d
# Frontend URL (for redirects)
FRONTEND_URL=https://your-ngrok-url.ngrok.io
# API Keys (optional for basic functionality)
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key
YAHOO_FINANCE_API_KEY=your_yahoo_finance_api_key- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API:
- Go to "APIs & Services" > "Library"
- Search for "Google+ API" and enable it
- Create OAuth 2.0 credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth 2.0 Client IDs"
- Choose "Web application"
- Add authorized redirect URIs (you'll update this after getting ngrok URL)
# Terminal 1: Start the application
npm run start:dev
# or
yarn start:dev
# Terminal 2: Start Cloudflare Tunnel
cloudflared tunnel --url http://localhost:3000- Copy the Cloudflare Tunnel URL (e.g.,
https://abc123.trycloudflare.com) - Update Google OAuth settings:
- Go back to Google Cloud Console
- Update the redirect URI to:
https://abc123.trycloudflare.com/api/v1/auth/google/callback
- Update your .env file:
GOOGLE_CALLBACK_URL=https://abc123.trycloudflare.com/api/v1/auth/google/callback FRONTEND_URL=https://abc123.trycloudflare.com
- Copy your Google credentials to the
.envfile:GOOGLE_CLIENT_ID=your_actual_client_id GOOGLE_CLIENT_SECRET=your_actual_client_secret
-
Visit the Google OAuth endpoint:
https://abc123.trycloudflare.com/api/v1/auth/google -
Complete the OAuth flow - you'll be redirected with a JWT token
-
Test protected endpoints:
# Get user profile (replace YOUR_JWT_TOKEN with the actual token) curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \ https://abc123.trycloudflare.com/api/v1/auth/profile
# Development
npm run start:dev # Start in watch mode
npm run start:debug # Start with debugger
npm run start:prod # Start in production mode
# Building
npm run build # Build the application
npm run format # Format code with Prettier
npm run lint # Lint code with ESLint
# Testing
npm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:cov # Run tests with coverage
npm run test:e2e # Run end-to-end tests
# Utilities
npm run clean # Clean all generated files
npm run clean:dist # Clean build output only
npm run clean:modules # Clean node_modules only| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/auth/google |
Initiate Google OAuth login |
| GET | /api/v1/auth/google/callback |
Google OAuth callback |
| POST | /api/v1/auth/refresh |
Refresh JWT token |
| GET | /api/v1/auth/profile |
Get current user profile (protected) |
| GET | /api/v1/auth/logout |
Logout user (protected) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/users |
Get all users (protected) |
| GET | /api/v1/users/:id |
Get user by ID (protected) |
| PATCH | /api/v1/users/:id |
Update user (protected) |
| DELETE | /api/v1/users/:id |
Delete user (protected) |
src/
βββ modules/
β βββ auth/ # Authentication module
β β βββ strategies/ # Passport strategies
β β βββ guards/ # JWT guards
β β βββ decorators/ # Custom decorators
β β βββ dto/ # Data transfer objects
β βββ user/ # User management
β βββ market/ # Market data
β βββ news/ # News aggregation
βββ config/ # Configuration
βββ common/ # Shared utilities
βββ types/ # TypeScript types
-
Start the application:
nvm use yarn start:dev
-
Start ngrok (in new terminal):
ngrok http 3000
-
Update .env with new ngrok URL (if it changed)
-
Update Google OAuth redirect URI (if ngrok URL changed)
# Test OAuth flow
curl -I https://your-ngrok-url.ngrok.io/api/v1/auth/google
# Test protected endpoint (after getting JWT token)
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
https://your-ngrok-url.ngrok.io/api/v1/auth/profile# Authenticate with Google Cloud
gcloud auth login
# Set your project
gcloud config set project your-project-id
# Deploy to Cloud Run
gcloud run deploy market-sum-api \
--source . \
--region=australia-southeast1 \
--allow-unauthenticatedUpdate your production environment variables:
NODE_ENV=production
GOOGLE_CALLBACK_URL=https://your-domain.com/api/v1/auth/google/callback
FRONTEND_URL=https://your-domain.com
JWT_SECRET=your_production_jwt_secret-
"Invalid redirect URI" error:
- Ensure ngrok URL is added to Google OAuth settings
- Check for trailing slashes or protocol mismatches
-
"JWT token invalid" error:
- Verify JWT_SECRET is set correctly
- Check token expiration
-
"Module not found" errors:
- Run
npm installoryarn install - Check Node.js version with
nvm use
- Run
-
ngrok URL changes:
- Update Google OAuth redirect URI
- Update .env file with new URL
LOG_LEVEL=debug- Authentication Setup Guide - Detailed OAuth setup
- Authentication Summary - Quick reference
- Environment Variables - Configuration template
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section above
- Review the authentication documentation
- Open an issue on GitHub
Note: This project is optimized for the Australian market with local data sources and compliance considerations.