This is a Next.js project that integrates Singapore's MyInfo with Reddit for user verification and flair management.
This project has been migrated from PostgreSQL to Firebase Realtime Database for cost-effectiveness (Firebase has a generous free tier!). The integration uses Firebase Admin SDK with service account authentication for secure server-side operations.
Create a .env.local file with the following Firebase configuration:
# Firebase Configuration (service account)
FIREBASE_SERVICE_ACCOUNT_KEY_BASE64=base64_encoded_service_account_json
FIREBASE_DATABASE_URL=https://your-project-id-default-rtdb.firebaseio.com/
# MyInfo Configuration
MYINFO_APP_REDIRECT_URL=your_myinfo_redirect_url
MYINFO_HOST=https://stg-id.singpass.gov.sg
MYINFO_APP_ID=your_myinfo_app_id
MYINFO_PRIVATE_ENC_KEY=your_private_encryption_key
MYINFO_PRIVATE_SIG_KEY=your_private_signing_key
# Reddit Configuration
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
REDDIT_REDIRECT_URI=your_reddit_redirect_uri
REDDIT_USER_AGENT=your_reddit_user_agent
# JWT Configuration
JWT_SECRET=your_jwt_secret_key- Create a Firebase project at Firebase Console
- Enable Realtime Database in your Firebase project
- Set up database rules (start with test mode for development):
{ "rules": { ".read": false, ".write": false, "subreddit_tokens": { ".read": "auth != null", ".write": "auth != null" } } } - Create a service account:
- Go to Project Settings > Service Accounts
- Click "Generate new private key"
- Download the JSON file
- Base64 encode the JSON content:
cat service-account.json | base64 - Set
FIREBASE_SERVICE_ACCOUNT_KEY_BASE64to the base64-encoded string
- Set the database URL in
FIREBASE_DATABASE_URL
The Firebase integration uses a service account for authentication, which provides:
- Server-side security: No client-side API keys exposed
- Fine-grained permissions: Service account can be restricted to specific operations
- Production ready: Suitable for deployment environments
Important: Keep your service account key secure and never commit it to version control. Use environment variables or secure secret management.
First, install dependencies:
npm installThen, run the development server:
npm run devOpen http://localhost:3000 with your browser to see the result.
Unlike PostgreSQL, Firebase Realtime Database doesn't require table creation. The database structure is created automatically when data is first written. You can still run the init command for compatibility:
npm run init-dbTo learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Firebase Realtime Database Documentation - learn about Firebase Realtime Database.
- Firebase Admin SDK Documentation - learn about Firebase Admin SDK.
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Make sure to add all your environment variables to your Vercel deployment settings. For the service account key, you can either:
- Add the entire JSON as a single environment variable
- Use Vercel's secret management features for enhanced security