Tarek Cheikh
Founder & AWS Cloud Architect
You're building your next big SaaS product. You've got the perfect idea, the technical skills, and the motivation. But then you hit the authentication wall. Again.
Sound familiar?
Every developer has been there. We've all wasted countless hours implementing user registration, login flows, password resets, and MFA — only to realize we're essentially rebuilding the same wheel for the nth time. Worse yet, popular authentication services like Auth0 or Okta can cost hundreds of dollars per month for even modest user bases.
That's exactly why I built CognitoApi — and today, I'm open-sourcing it for the community.
Let's talk numbers. Most authentication-as-a-service providers charge based on Monthly Active Users (MAUs). Here's what you're looking at:
For bootstrapped startups and indie developers, these costs are prohibitive. But rolling your own auth system? That's a security nightmare waiting to happen.
CognitoApi is a fully automated, production-ready authentication API built on AWS Cognito. Here's the kicker: it's completely free for your first 50,000 users.
Yes, you read that right. 50K users. Free.
git clone https://github.com/TocConsulting/cognito-api.git
cd terraform
ENVIRONMENT=dev make apply
Three commands. That's it. Your entire authentication infrastructure is deployed, configured, and ready to use.
Every aspect of user management is handled through simple REST endpoints:
CognitoApi leverages a serverless architecture that automatically scales with your user base.
Key Components:
Let's look at a typical authentication flow:
// Step 1: User Login
POST /v1/login
{
"email": "user@example.com",
"password": "SecurePassword123!"
}
// Response
{
"email": "user@example.com",
"verification_session": "AYABeLHXhc...",
"verification_type": "SOFTWARE_TOKEN_MFA"
}
// Step 2: MFA Verification
POST /v1/mfa-verify
{
"email": "user@example.com",
"verification_type": "SOFTWARE_TOKEN_MFA",
"verification_session": "AYABeLHXhc...",
"otp_code": "123456"
}
// Response
{
"id_token": "eyJraWQiOiJp...",
"access_token": "eyJraWQiOiJu...",
"refresh_token": "eyJjdHkiOiJK...",
"expires_in": 3600
}
Clean, simple, secure. No complexity hidden from you, yet all the heavy lifting is handled.
Here's what running CognitoApi costs for different user scales:
Compare that to Auth0's $240/month for just 1,000 users. The savings are astronomical.
1. Prerequisites
# Install required tools
brew install terraform
brew install awscli
2. Configure Your Environment
# terraform/environments/dev/terraform.tfvars.dev
aws-region = "us-east-1"
auth-api-dns-name = "auth.yourapp.com"
cognito-reply-to-email-address = "hello@yourapp.com"
3. Deploy
export AWS_PROFILE=YourProfile
ENVIRONMENT=dev make plan
ENVIRONMENT=dev make apply
In under 10 minutes, you have a production-ready authentication system.
Want to see CognitoApi in action before integrating it into your own project? I've built a complete React example application that demonstrates every feature of the authentication system.
The CognitoApi React Example App is a modern, responsive application that showcases:
The example app is built with modern web technologies:
// Modern React with Vite
cognito-api-react-example-app/
├── src/
│ ├── App.jsx // Main auth flow component
│ ├── services/
│ │ └── ApiService.js // CognitoApi integration
│ └── config.js // Environment configuration
Getting the example app running is incredibly simple:
# 1. Clone the example app
git clone https://github.com/TocConsulting/cognito-api-react-example-app.git
cd cognito-api-react-example-app
# 2. Install dependencies
npm install
# 3. Configure your CognitoApi endpoint
echo "VITE_API_URL=https://your-cognito-api.com" > .env.local
echo "VITE_API_KEY=your_api_key_here" >> .env.local
# 4. Start the development server
npm run dev
Visit http://localhost:3000 and experience the entire authentication flow!
Here's what your users will experience:
1. Registration
2. Email Confirmation
3. MFA Setup
4. Secure Login
The example app demonstrates best practices for integrating CognitoApi:
// Clean API service abstraction
class ApiService {
async register(userData) {
const response = await fetch(`${API_URL}/v1/users`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify(userData)
});
return response.json();
}
async verifyMFA(mfaData) {
// Handles the two-step authentication flow
// Returns JWT tokens on success
}
async refreshToken(refreshToken) {
// Keeps users logged in seamlessly
}
}
The example app isn't just a demo — it's a solid foundation for your own authentication UI:
The example app also shows advanced patterns:
If you're building your own UI, here's how simple the integration is:
const login = async (email, password) => {
// Step 1: Initial login
const loginResponse = await fetch(`${API_URL}/v1/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify({ email, password })
});
const { verification_session } = await loginResponse.json();
// Step 2: MFA verification
const mfaCode = prompt('Enter MFA code:');
const mfaResponse = await fetch(`${API_URL}/v1/mfa-verify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify({
email,
verification_type: 'SOFTWARE_TOKEN_MFA',
verification_session,
otp_code: mfaCode
})
});
const tokens = await mfaResponse.json();
// Store tokens securely
localStorage.setItem('access_token', tokens.access_token);
};
Security isn't an afterthought with CognitoApi — it's the foundation:
Every user must set up TOTP-based MFA. No exceptions. This alone prevents 99.9% of account takeover attempts.
All sensitive data, including MFA QR codes, are stored in encrypted S3 buckets with strict access policies.
CognitoApi isn't just about authentication — it's about giving you back your time to focus on what matters: your product.
Complete API Documentation
Monitoring and Observability
Multi-Environment Support
# Development
ENVIRONMENT=dev make apply
# Staging
ENVIRONMENT=staging make apply
# Production
ENVIRONMENT=prod make apply
CognitoApi is MIT licensed and completely open source. This means:
SaaS Startups
Perfect for B2B SaaS products that need enterprise-grade security without enterprise prices.
Mobile Applications
RESTful API design makes integration with iOS and Android apps seamless.
Microservices Architecture
Each Lambda function is isolated, making it easy to scale specific auth operations independently.
Compliance Requirements
Built-in audit trails and secure storage help meet GDPR, HIPAA, and other compliance needs.
Ready to stop reinventing the authentication wheel? Here's your action plan:
1. Clone the Repository
git clone https://github.com/TocConsulting/cognito-api.git
2. Try the Example App
git clone https://github.com/TocConsulting/cognito-api-react-example-app.git
3. Check the Documentation
Visit cognito-api.com for comprehensive guides
4. Join the Community
Star the repo, open issues, contribute improvements
5. Deploy Your First Instance
Follow the quick start guide above
Authentication is a solved problem. It's time we treated it that way.
CognitoApi gives you enterprise-grade authentication infrastructure for the price of a coffee. It's secure, scalable, and most importantly — it just works.
Stop spending weeks building auth flows. Stop paying hundreds of dollars for basic user management. Start building the features that actually differentiate your product.
Your users are waiting. What are you going to build for them today?
This article is just the start. Get the full picture with our free whitepaper - 8 chapters covering IAM, S3, VPC, monitoring, agentic AI security, compliance, and a prioritized action plan with 50+ CLI commands.
A complete beginner-to-builder guide for AWS SAM with Python. Learn to create, test locally, deploy, debug, and manage serverless APIs step by step.
How I built a secure, scalable file sharing solution using AWS Lambda, API Gateway, and Cognito with zero infrastructure to manage and 91% cost reduction.
Stop sending your IAM policies, CloudTrail logs, and infrastructure code to third-party APIs. Run LLMs locally with Ollama on Apple Silicon — private, offline, fast. Complete setup guide with AWS security use cases.