A Node.js backend application for a cake/bakery platform with Firebase Authentication integration.
- Dual Authentication System: Firebase Auth + PostgreSQL database
- User Management: Registration and login with JWT tokens
- Baker Profiles: Support for baker-specific business information
- API Documentation: Swagger/OpenAPI documentation
- Database: PostgreSQL with Sequelize ORM
- File Storage: Avatar images stored as URL strings
- Node.js + Express.js
- PostgreSQL + Sequelize ORM
- Firebase Auth + Firestore
- JWT Authentication
- Swagger Documentation
- bcryptjs for password hashing
-
Install Dependencies
npm install
-
Environment Variables Create a
.envfile with the following variables:# Database Configuration DB_HOST=your_postgres_host DB_PORT=5432 DB_USER=your_postgres_user DB_PASSWORD=your_postgres_password DB_NAME=your_database_name # JWT Secret JWT_SECRET=your_jwt_secret_key # Firebase Configuration FIREBASE_API_KEY=your_firebase_api_key FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com FIREBASE_PROJECT_ID=your_project_id FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id FIREBASE_APP_ID=your_app_id # Server Port PORT=3000
-
Start Development Server
npm run dev
-
POST /api/auth/register- Register a new user- Body:
{ username, email, password, full_name, avatar } - Creates user in both Firebase Auth and PostgreSQL
- Returns JWT token and user data
- Body:
-
POST /api/auth/login- Login user- Body:
{ email, password } - Authenticates with Firebase Auth
- Returns JWT token and user data
- Body:
Access Swagger documentation at: http://localhost:3000/docs
id- Primary keyusername- Unique usernameemail- Unique emailpassword- Hashed passwordfull_name- User's full nameavatar- Avatar image URL (string)firebase_uid- Firebase Auth UIDis_admin- Admin flagis_baker- Baker flag
user_id- Foreign key to usersbusiness_name- Baker's business namebusiness_address- Business addressphone_number- Contact numberspecialty- Baker's specialtybio- Business descriptionis_verified- Verification status
- Users are created in both Firebase Auth and PostgreSQL
- Firebase UID is stored in PostgreSQL for reference
- Authentication is handled by Firebase, user data by PostgreSQL
- Firestore documents are created for chat functionality
- Avatars are stored as URL strings, not uploaded to Firebase Storage
- Frontend should handle image uploads and provide URL to backend
- Firebase Auth errors are properly handled and mapped to appropriate HTTP responses
- Duplicate email/username errors from both systems are handled