Skip to content

SzaBee13/example-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Szabi Auth with 2FA

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.


πŸš€ Features

  • 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

πŸ› οΈ Tech Stack

  • Backend: Node.js, Express, speakeasy (for 2FA), jsonwebtoken
  • Frontend: React, TailwindCSS, Axios
  • Storage: JSON file for users

πŸ“¦ Installation

  1. Clone the repo

    git clone https://your-repo-url.git
    cd your-repo-folder
  2. Install backend deps

    cd backend
    npm install
  3. Start backend

    node index.js
  4. Install frontend deps

    cd ../frontend
    npm install
  5. Start frontend

    npm run dev

βš™οΈ Usage

  • 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)

πŸ”§ CORS Fix

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.


πŸ€” Why?

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!


πŸ™Œ Contributions

PRs welcome! Hit me up if you wanna collab or have ideas.


Copy-paste and customize! Need it tweaked? Just say the word.

About

Example Authentication

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published