This project is a serverless authentication app designed for learning and prototyping.
Users can:
- Register accounts
- Login securely
- Store hashed passwords
- Separate admin vs normal users
- Allow admin-only user management
This project demonstrates how to build a simple login/register system without running a traditional server, using:
✅ Cloudflare Workers (backend API)
✅ Cloudflare D1 (database)
✅ Cloudflare Pages (frontend hosting)
✅ Vanilla HTML/CSS/JS frontend
✅ SHA-256 password hashing
Frontend (Cloudflare Pages)
↓ fetch()
Cloudflare Worker API
↓
Cloudflare D1 Database (SQLite)
node-auth-app/
│
├── worker.js # Backend API (Cloudflare Worker)
├── wrangler.toml # Worker configuration
│
├── public/
│ ├── index.html # UI
│ ├── css/style.css # Styling
│ └── js/main.js # Frontend logic
│
└── README.md
- Register account
- Login securely
- Password hashing (SHA-256)
- Clean UI
- View all users
- Delete users
- Admin-only access control
git clone https://github.com/YOUR_USERNAME/node-auth-app.git
cd node-auth-appnpm install -g wranglerLogin:
wrangler loginwrangler d1 create node-auth-dbCopy the database ID into wrangler.toml.
wrangler d1 execute node-auth-db --command "
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE,
password TEXT,
role TEXT
);
"Admin password = 1234
wrangler d1 execute node-auth-db --command "
INSERT INTO users (username,password,role)
VALUES (
'admin',
'03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4',
'admin'
);
"wrangler deployYou’ll get:
https://your-worker.workers.dev
Push repo to GitHub and connect to Cloudflare Pages:
Settings:
Build command: (none)
Output directory: /public
Deploy.
You’ll get:
https://your-site.pages.dev
In main.js, set:
const API = "https://your-worker.workers.dev";✅ Passwords are hashed ❌ No JWT/session yet (learning project) ❌ Admin auth uses header role check
For production:
- Add JWT authentication
- Add rate limiting
- Use HTTPS-only cookies
This project teaches:
- Serverless backend design
- Edge computing basics
- REST API building
- Auth system design
- Database integration
- Role-based access control
- JWT login sessions
- Password salting
- Email verification
- UI framework (React/Vue)
- OAuth login
Built using:
- Cloudflare Workers
- Cloudflare D1
- Cloudflare Pages