snackify-auth is a Node.js API that i coded from scratch, for secure user authentication, complete with:
- user registration & login (passwords are securely hashed)
- 2-factor authentication (2FA) via email to keep your logins super safe
- JWT tokens for session management and route protection
- a profile route accessible only with a valid token
- a recipe recommendation engine that pops out recipes based on your ingredients and dietary preferences
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
- 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
POST /api/auth/register
{
"name": "tina",
"email": "tina@example.com",
"password": "strongpassword",
"food_pref": "veg"
}{
"message": "user registered successfully"
}POST /api/auth/login
{
"email": "tina@example.com",
"password": "strongpassword"
}{
"message": "2FA code sent to your email"
}2FA code is sent via email
POST /api/auth/verify2fa
{
"email": "tina@example.com",
"code": "123456"
}{
"message": "2FA verification successful",
"token": "<jwt-token>"
}use this JWT token to access protected routes.
GET /api/auth/profile
Authorization: Bearer <jwt-token>
{
"id": "user-uuid",
"name": "tina",
"email": "tina@example.com",
"food_pref": "veg"
}POST /api/recommend
{
"ingredients": ["rice", "garlic"],
"preference": "non-veg"
}[
{
"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.
-
clone the repo
git clone <repo-url>
-
install dependencies
npm install
-
make a
.envfile: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 -
run the server
npm run dev
or
node src/server.js
-
test with Postman, curl, or your own frontend
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.