A simple Node.js + Express backend with JSON user storage and TOTP 2FA, paired with a React + TailwindCSS frontend.
Perfect for learning token-based auth with a dash of security sauce.
- User registration with optional 2FA (Google Authenticator, Authy, etc.)
- Login with username, password, and 2FA token
- JWT token issuance after successful login
- Users stored in a local JSON file (easy peasy storage)
- Frontend in React + TailwindCSS for a clean UI
- Backend: Node.js, Express,
speakeasy(for 2FA),jsonwebtoken - Frontend: React, TailwindCSS, Axios
- Storage: JSON file for users
-
Clone the repo
git clone https://your-repo-url.git cd your-repo-folder -
Install backend deps
cd backend npm install -
Start backend
node index.js
-
Install frontend deps
cd ../frontend npm install -
Start frontend
npm run dev
- Register a user, toggle 2FA if you want
- If 2FA enabled, scan the QR with your Authenticator app
- Login with your creds + 2FA code (if enabled)
- Receive JWT token on success
- Use token to access protected routes (not included, but easy to add)
Make sure your backend allows requests from your frontend origin by adding this to your backend code:
const cors = require('cors')
app.use(cors({ origin: 'http://localhost:5173', credentials: true }))Replace http://localhost:5173 with your frontend URL.
Just a fun project to learn real-world authentication flows with 2FA and tokens. You can extend it to use databases, refresh tokens, or anything you want!
PRs welcome! Hit me up if you wanna collab or have ideas.
Copy-paste and customize! Need it tweaked? Just say the word.