Skip to content

Commit 89de93f

Browse files
authored
Update ecommerce instructions (#340)
1 parent 86f275c commit 89de93f

File tree

16 files changed

+94
-9985
lines changed

16 files changed

+94
-9985
lines changed

starters/nextjs/firebase-ecommerce/.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ vsce-debug.log*
4040
# Firebase
4141
firebase-debug.log*
4242
firebase-debug.*
43-
.firebase
43+
.firebase
44+
.firebaserc
45+
46+
# dataconnect
47+
dataconnect-generated/
48+
dataconnect/.dataconnect/

starters/nextjs/firebase-ecommerce/README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ The application provides a quick and easy to use shopping experience with featur
2828

2929
1. Create a new Firebase project in the [Firebase Console](https://console.firebase.google.com).
3030
2. Enable **Email/Password Authentication**.
31-
3. Add Firebase app secrets to `.env.local`.
32-
4. Include Firebase app secrets in **App Hosting**.
31+
3. Replace the relevant commented-out environment variables in `apphosting.yaml`
32+
with your firebase config.
3333

3434
#### Firebase Data Connect
3535

3636
1. Install the **Firebase Data Connect** extension for VS Code.
3737
2. Create a new Data Connect instance and service.
3838
3. Set up billing for the Firebase project.
3939
4. Switch to the Blaze plan.
40-
5. Define the required schema, queries, and mutations.
40+
5. Modify `dataconnect/dataconnect.yaml` to specify `serviceId`, `location`,
41+
`schema.datasource.postgresql.database` and
42+
`schema.datasource.postgressql.cloudSql.instanceId`
4143
6. Deploy the schema, queries, and mutations to production.
4244

4345
#### Firebase Storage
@@ -48,13 +50,18 @@ The application provides a quick and easy to use shopping experience with featur
4850
#### Firebase App Hosting
4951

5052
1. Connect the Firebase app to your GitHub repository.
51-
2. Create a new backend for the application.
52-
3. Deploy secrets to app hosting using the Firebase CLI.
53-
4. Deploy the application to Firebase Hosting.
53+
2. Create a new backend for the application, but do not deploy yet.
54+
We need to set up environment variables first for the app to work.
5455

5556
### Stripe Setup
5657

5758
1. Create a new Stripe account.
59+
2. Follow the instructions in apphosting.yaml to create the
60+
public and private keys for your stripe application.
61+
3. Create a webhook that listen to "Events on your account" at
62+
<your domain>/api/stripe/webhook that receives at least
63+
the following events: `payment_intent.succeeded`, `payment_intent.failed`,
64+
`charge.succeeded`, `charge.updated`.
5865
2. Add API keys (Publishable and Secret) to `.env.local`.
5966
3. Set up a webhook endpoint in the Firebase project.
6067
4. Add the webhook secret to `.env.local`.
@@ -63,12 +70,18 @@ The application provides a quick and easy to use shopping experience with featur
6370

6471
## Environment Variables
6572

66-
The following environment variables must be configured in `.env.local`:
73+
The following environment variables must be configured in `apphosting.yaml`
74+
(there are comments for where to find these values)
6775

68-
- **Firebase Secrets**: `NEXT_PUBLIC_FIREBASE_API_KEY`, `NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN`, `NEXT_PUBLIC_FIREBASE_PROJECT_ID`, `NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET`, `NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID`, `NEXT_PUBLIC_FIREBASE_APP_ID`.
69-
- **Stripe Secrets**: `NEXT_PUBLIC_STRIPE_PUB_KEY`, `STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET`
76+
- **Firebase Config**: `NEXT_PUBLIC_FIREBASE_API_KEY`, `NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN`, `NEXT_PUBLIC_FIREBASE_PROJECT_ID`, `NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET`, `NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID`, `NEXT_PUBLIC_FIREBASE_APP_ID`.
77+
- **Stripe Config**: `NEXT_PUBLIC_STRIPE_PUB_KEY`, `STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET`
7078
- **Google/Gemini API Key**: `GOOGLE_API_KEY`
7179

80+
## Deploy
81+
Once you have set up Stripe, Data Connect, and configured your App Hosting environment, it's time to deploy!
82+
If you have automatic rollouts enabled, simply push your changes. Otherwise, after pushing, go to the
83+
Firebase console and click "Create Rollout".
84+
7285
## Application Features
7386

7487
### Homepage
@@ -148,18 +161,17 @@ To run this project locally, follow these steps:
148161
```
149162
npm install
150163
```
151-
4. Copy the example environment variables:
152-
```
153-
cp .env.example .env.local
154-
```
155-
• Fill in the required values (Firebase config, Stripe keys, Google API key, etc.).
156-
5. Start the development server:
164+
4. Fill in `apphosting.yaml` as guided by the comments.
165+
5. Initialize the firebase emulator suite with `firebase init emulators`. You may
166+
create an `apphosting.emulator.yaml` if you choose to use different configurations
167+
during local development or you can test against your production config.
168+
5. Start the emulator
157169
```
158-
npm run dev
170+
firebase emulators:start
159171
```
160172
6. Open the application in your browser at:
161173
```
162-
http://localhost:3000
174+
http://localhost:5002
163175
```
164176

165177
---

starters/nextjs/firebase-ecommerce/apphosting.yaml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,46 @@ runConfig:
44
minInstances: 0
55

66
# Environment variables and secrets.
7+
# Grant access to secrets in Cloud Secret Manager.
8+
# See https://firebase.google.com/docs/app-hosting/configure#secret-parameters
9+
# If you would like to change any keys' values in local development with the emulator
10+
# (e.g. using Stripe Sandbox keys), you can overwrite values in apphosting.emulator.yaml
711
env:
8-
# Grant access to secrets in Cloud Secret Manager.
9-
# See https://firebase.google.com/docs/app-hosting/configure#secret-parameters
10-
- variable: NEXT_PUBLIC_FIREBASE_API_KEY
11-
secret: FIREBASE_API_KEY
12-
- variable: NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
13-
secret: FIREBASE_AUTH_DOMAIN
14-
- variable: NEXT_PUBLIC_FIREBASE_PROJECT_ID
15-
secret: FIREBASE_PROJECT_ID
16-
- variable: NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
17-
secret: FIREBASE_STORAGE_BUCKET
18-
- variable: NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID
19-
secret: FIREBASE_MESSAGING_SENDER_ID
20-
- variable: NEXT_PUBLIC_FIREBASE_APP_ID
21-
secret: FIREBASE_APP_ID
22-
- variable: GOOGLE_API_KEY
23-
secret: GOOGLE_API_KEY
24-
- variable: STRIPE_ACCOUNT_ID
25-
secret: STRIPE_ACCOUNT_ID
26-
- variable: STRIPE_SECRET_KEY
27-
secret: STRIPE_SECRET_KEY
28-
- variable: NEXT_PUBLIC_STRIPE_PUB_KEY
29-
secret: STRIPE_PUB_KEY
30-
- variable: STRIPE_WEBHOOK_SECRET
31-
secret: STRIPE_WEBHOOK_SECRET
12+
# Values for Firebase config can be found by clicking the cog next to "Project Overview"
13+
# in the firebase console and clicking "project settings"
14+
# - variable: NEXT_PUBLIC_FIREBASE_API_KEY
15+
# value: <YOUR VALUE HERE>
16+
# - variable: NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
17+
# value: <YOUR VALUE HERE>
18+
# - variable: NEXT_PUBLIC_FIREBASE_PROJECT_ID
19+
# value: <YOUR VALUE HERE>
20+
# - variable: NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
21+
# value: <YOUR VALUE HERE>
22+
# - variable: NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID
23+
# value: <YOUR VALUE HERE>
24+
# - variable: NEXT_PUBLIC_FIREBASE_APP_ID
25+
# value: <YOUR VALUE HERE>
26+
27+
# The Google API key needs access to the Generative AI APIs. Create your key by visiting
28+
# https://ai.google.dev/gemini-api/docs and clicking "Get a Gemini API Key"
29+
# You can then run `firebase apphosting:secrets:set google-api-key and pasting the value.
30+
# - variable: GOOGLE_API_KEY
31+
# secret: google-api-key
32+
33+
# To use stripe, you must create an account on stripe.com. From the stripe dashboard
34+
# You can copy the NEXT_PUBLIC_STRIPE_PUB_KEY from "Publishable key" in the dashboard.
35+
# You can set STRIPE_SECRET_KEY by calling `firebase apphosting:secrets:set stripe-secret-key`
36+
# and pasting the value listed as "Secret key" in the dashboard.
37+
# To get the stripe webhook secret, create a stripe webhook as described in README.md,
38+
# go to the webhook details page and click "Reveal" under "Signing secret". Copy that value,
39+
# run `firebase apphosting:secrets:set stripe-webhook-secret` and paste the secret value when
40+
# prompted. The value for STRIPE_ACCOUNT_ID can be found in the upper right corner of the
41+
# webhook details page.
42+
# - variable: NEXT_PUBLIC_STRIPE_PUB_KEY
43+
# value: <YOUR VALUE HERE>
44+
# - variable: STRIPE_SECRET_KEY
45+
# secret: stripe-secret-key
46+
# - variable: STRIPE_ACCOUNT_ID
47+
# value: <YOUR VALUE HERE>
48+
# - variable: STRIPE_WEBHOOK_SECRET
49+
# secret: stripe-webhook-secret

0 commit comments

Comments
 (0)