Skip to content

maithilimukherjee/snackify-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snackify-auth

about the project

snackify-auth is a Node.js API that i coded from scratch, for secure user authentication, complete with:

  1. user registration & login (passwords are securely hashed)
  2. 2-factor authentication (2FA) via email to keep your logins super safe
  3. JWT tokens for session management and route protection
  4. a profile route accessible only with a valid token
  5. a recipe recommendation engine that pops out recipes based on your ingredients and dietary preferences

skills demonstrated

through building this API, you’ll see:

  • backend development: Node.js, Express, PostgreSQL, Neon DB for user and recipe data
  • authentication & security: bcrypt password hashing, 2FA, JWT-based route protection
  • email integration: real-time 2FA via nodemailer
  • api design: registration, login, verification, profile, and recommendations endpoints
  • algorithmic thinking: matching recipes based on user input, preference, and healthiness
  • config management: all sensitive creds managed via .env
  • error handling: neat responses for expired codes, invalid input, and unauthorized requests

technologies & tools

  • backend: Node.js, Express.js, PostgreSQL, Neon DB
  • authentication: bcrypt, JWT, nodemailer for 2FA
  • utilities: uuid, dotenv
  • data: JavaScript (in-memory recipes), PostgreSQL
  • testing: Postman, curl
  • version control: Git & GitHub

endpoints & usage

1. register

POST /api/auth/register

body:

{
  "name": "tina",
  "email": "tina@example.com",
  "password": "strongpassword",
  "food_pref": "veg"
}

response:

{
  "message": "user registered successfully"
}

2. login

POST /api/auth/login

body:

{
  "email": "tina@example.com",
  "password": "strongpassword"
}

response:

{
  "message": "2FA code sent to your email"
}

2FA code is sent via email


3. verify 2FA

POST /api/auth/verify2fa

body:

{
  "email": "tina@example.com",
  "code": "123456"
}

response:

{
  "message": "2FA verification successful",
  "token": "<jwt-token>"
}

use this JWT token to access protected routes.


4. get profile

GET /api/auth/profile

headers:

Authorization: Bearer <jwt-token>

response:

{
  "id": "user-uuid",
  "name": "tina",
  "email": "tina@example.com",
  "food_pref": "veg"
}

5. recommend recipes

POST /api/recommend

body:

{
  "ingredients": ["rice", "garlic"],
  "preference": "non-veg"
}

response:

[
  {
    "name": "chicken fried rice",
    "ingredients": ["rice", "chicken", "onion", "garlic", "soy sauce", "carrot"],
    "healthy": true,
    "type": "non-veg",
    "score": 2
  }
  // ...top 3 best matches returned
]

filters for food preference and matches recipes using your provided ingredients.


setup & running

  1. clone the repo

    git clone <repo-url>
  2. install dependencies

    npm install
  3. make a .env file:

    DATABASE_URL=your-neon-db-url
    MAIL_HOST=smtp.ethereal.email
    MAIL_PORT=587
    MAIL_USER=your-ethereal-user
    MAIL_PASS=your-ethereal-pass
    MAIL_FROM="snackify <your-email>"
    JWT_SECRET=supersecretkey
    JWT_EXPIRES=1d
    
  4. run the server

    npm run dev

    or

    node src/server.js
  5. test with Postman, curl, or your own frontend


closing thoughts

this project is my mashup of two things i love: coding & cooking.
it’s secure, practical and proof that backend skills, security best-practices, and a little personal flavor can combine into something both useful and fun.

About

snackify-auth is a nodejs api that i engineered from scratch, featuring a complete secure authentication system along with an intelligent recipe recommendation engine that suggests meals based on a user's available ingredients and food preferences.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages