A simple Node.js API service with Firebase authentication, user management, and Swagger documentation.
- Authentication: Firebase-based user authentication
- User Management: Create, read, update, and delete user profiles
- API Documentation: Auto-generated Swagger/OpenAPI documentation
- Vercel Ready: Configured for easy deployment to Vercel
GET /- Welcome messageGET /hello- Returns "Hello from Vercel"POST /palindrome- Returns palindrome of a wordGET /palindrome/:word- Returns palindrome via URL parameter
POST /auth/register- Register a new userPOST /auth/verify-token- Verify a Firebase ID tokenGET /auth/user- Get current user profile (requires auth)PUT /auth/user- Update user profile (requires auth)DELETE /auth/user- Delete user account (requires auth)
npm install- Create a Firebase project at Firebase Console
- Enable Authentication and Firestore Database
- Generate a service account key:
- Go to Project Settings > Service Accounts
- Click "Generate New Private Key"
- Download the JSON file
Create a .env file in the root directory:
# Option 1: Using individual environment variables
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour-Private-Key-Here\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com
FIREBASE_DATABASE_URL=https://your-project-id.firebaseio.com
# Option 2: Using base64 encoded service account (recommended for Vercel)
# Encode your service account JSON: base64 -i serviceAccountKey.json
FIREBASE_SERVICE_ACCOUNT_BASE64=your-base64-encoded-service-account-jsonnpm start
# or for development with auto-reload
npm run devAccess the API at:
- API: http://localhost:3000
- Swagger UI: http://localhost:3000/api-docs
npm i -g vercelFor Vercel deployment, it's recommended to use the base64 encoded service account:
-
Encode your service account JSON:
base64 -i path/to/serviceAccountKey.json
-
Add the environment variable in Vercel:
- Go to your Vercel project settings
- Navigate to Environment Variables
- Add
FIREBASE_SERVICE_ACCOUNT_BASE64with the encoded value
vercel- Use Firebase SDK to authenticate users on the client
- Get the ID token:
const idToken = await user.getIdToken() - Include the token in API requests:
Authorization: Bearer ${idToken}
curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "secure123",
"displayName": "John Doe"
}'curl -X GET http://localhost:3000/auth/user \
-H "Authorization: Bearer YOUR_ID_TOKEN"- All sensitive user operations require authentication
- Firebase ID tokens are verified on each request
- User data is stored securely in Firestore
- Passwords are managed by Firebase Auth (never stored directly)
The API documentation is automatically generated and available at /api-docs when running the server. The standalone OpenAPI specification is also available in swagger.json.
- Ensure all required environment variables are set
- Check that the service account key is valid
- Verify Firebase project settings
- Ensure the ID token is valid and not expired
- Check that the Authorization header format is correct:
Bearer TOKEN - Verify the user exists in Firebase Auth
ISC