Setup Service Accounts
Service accounts are necessary for secure backend operations in ShipFast. Follow the steps below to create and configure a service account.
Steps:
1. Generate a Service Account Key
- Go to the Firebase Console (opens in a new tab).
- Select your project from the list.
- Click on the gear icon next to "Project Overview" in the left sidebar and select "Project settings".
- Navigate to the "Service accounts" tab.
- Click on "Generate new private key". A JSON file will be downloaded to your computer.
2. Copy the JSON File Content
-
Open the downloaded service account JSON file.
-
Copy its entire content. The file will look similar to this:
{ "type": "service_account", "project_id": "your-project-id", "private_key_id": "your-private-key-id", "private_key": "-----BEGIN PRIVATE KEY-----\\nYOUR-PRIVATE-KEY\\n-----END PRIVATE KEY-----\\n", "client_email": "your-client-email", "client_id": "your-client-id", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-client-email", "universe_domain": "googleapis.com" }
3. Add the Service Account to Your Project
- Locate the
firebase-service-account.json
file in the root directory of your project. - Replace its content with the copied JSON content.
The service account is now set up and ready to use.
Why Service Accounts are Required
In ShipFast, we recommend hosting the app on platforms like Vercel, as it fully supports Next.js API routes for handling server-side operations, including integrations with Stripe and Firebase. You can learn more about Next.js API routes here (opens in a new tab).
One of the API routes that ShipFast relies on is the api/stripe/events
, which records Stripe transactions. When a payment is completed in Stripe, this API route is triggered to process the data sent by Stripe, such as payment status or subscription updates. It then securely stores the information in the Firestore database, ensuring that the app is aware of the current user subscription and credits.
Since the API route is hosted separately from Firebase, authentication is required to securely access Firestore and other services. This is done using a service account, which ensures secure communication between the ShipFast (where it is deployed, recommended on Vercel) and Firebase, without exposing sensitive credentials.
Once the service account is configured, the backend can securely interact with Firebase, process Stripe payments, and perform other necessary operations.