Generating Firebase Admin SDK Key
To allow your backend (Cloud Functions or local scripts) to interact with Firebase services with full privileges, you need a service account key. Follow these steps to generate one.
Access Console
Sign in to the Firebase Console and select your project.
Navigate to Settings
Navigate to Project settings (gear icon) > Service accounts.
Locate Admin SDK Section
Under the "Firebase Admin SDK" section, click the Generate new private key button.
Confirm Generation
A confirmation dialog will appear. Click Generate key to confirm.
Download Key
The JSON file containing your service account credentials will be downloaded to your computer automatically.
This file contains sensitive credentials. Do not commit it to public repositories (like GitHub). Add it to your .gitignore file.
Steps to deploy the function in GCP
To configure the Google Cloud CLI (gcloud) for your project myconcierge-485306 and deploy the functions defined in index.js, follow the steps below.
1. Configure gcloud
First, ensure you are authenticated and targeting the correct project.
# 1. Login to Google Cloud
gcloud auth login
# 2. Set the project ID
gcloud config set project myconcierge-485306
# 3. (Optional) Set a default region (e.g., us-central1) to avoid specifying it every time
gcloud config set functions/region us-central1
2. Enable Required APIs
If this is the first time you are deploying functions via gcloud for this project, you need to enable the Cloud Functions and Cloud Build APIs:
gcloud services enable cloudfunctions.googleapis.com cloudbuild.googleapis.com artifactregistry.googleapis.com
3. Deploy the Functions
Since your index.js exports multiple functions, you must deploy them individually. Run the following commands from the gcp_deployment directory.
Note: I am using the nodejs20 runtime. Ensure your local Node.js version matches or is compatible.
gcloud functions deploy createServiceRequest \
--gen2 \
--runtime=nodejs20 \
--region=us-central1 \
--trigger-http \
--allow-unauthenticated \
--entry-point=createServiceRequest \
--source .
gcloud functions deploy updateRequestStatus \
--gen2 \
--runtime=nodejs20 \
--region=us-central1 \
--trigger-http \
--allow-unauthenticated \
--entry-point=updateRequestStatus \
--source .
gcloud functions deploy getGuestRequests \
--gen2 \
--runtime nodejs20 \
--region=us-central1 \
--trigger-http \
--allow-unauthenticated \
--entry-point=getGuestRequests \
--source .
gcloud functions deploy getServiceRequests \
--gen2 \
--runtime nodejs20 \
--region=us-central1 \
--trigger-http \
--allow-unauthenticated \
--entry-point=getServiceRequests \
--source .
gcloud functions deploy getMenuItems \
--gen2 \
--runtime nodejs20 \
--region=us-central1 \
--trigger-http \
--allow-unauthenticated \
--entry-point=getMenuItems \
--source .
Summary of Flags
- --runtime nodejs20: Specifies the Node.js environment.
- --trigger-http: Indicates these are HTTP-triggered functions (Webhooks/APIs).
- --allow-unauthenticated: Makes the function publicly accessible (required for standard HTTP requests unless you implement IAM auth).
- --source .: Uploads the current directory code.
Deploy API Configuration
Deploy the Configuration
Run the following command in your terminal to deploy the service configuration to Google Cloud. This creates a managed service named hotel-api.endpoints.myconcierge-485306.cloud.goog.
gcloud endpoints services deploy openapi2-functions.yaml --project myconcierge-485306
Enable the Service
Once the deployment finishes, enable the newly created service so it can process traffic:
gcloud services enable hotel-api.endpoints.myconcierge-485306.cloud.goog --project myconcierge-485306
Generating a New Flutter Project
To generate a new Flutter project, you use the flutter create command in your terminal.
Basic Syntax
flutter create <project_name>
Examples
This creates a project with the default settings (Android, iOS, Web, Linux, macOS, Windows).
flutter create my_concierge
This sets the package name (e.g., com.example.my_concierge), which is important for publishing to app stores.
flutter create --org com.example my_concierge
If you only want to generate code for specific platforms (e.g., only Android and iOS).
flutter create --platforms android,ios my_concierge
By default, Flutter uses Kotlin for Android and Swift for iOS. You can change this if needed (though defaults are recommended).
flutter create --android-language java --ios-language objc my_concierge
Next Steps
Once created, navigate into your project folder and run it:
cd my_concierge_app
flutter run
FlutterFire Configuration
Step 1: Generate Configuration
Run the following command in your terminal (inside the my_concierge_app directory). Select your project (myconcierge-485306) and the platforms you are targeting (iOS, Android).
flutterfire configure
If you don't have the CLI installed, run dart pub global activate flutterfire_cli first.
Step 2: Update main.dart
Once the firebase_options.dart file is generated in your lib folder, update your main.dart to use it.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(HotelConciergeApp());
}
Backend Updates for User Management
To address your requirements, I will update the backend code to handle user synchronization and management.
index.js
- onUserSignup: A new background trigger that listens for new users created in Firebase Authentication and automatically writes a default profile to the Firestore users collection.
- updateUserDetails: A new HTTP endpoint allowing Staff to update a guest's profile with specific details like name, room number, and stay validity dates.
openapi2-functions.yaml
Added the /user/update endpoint definition so it can be deployed to the API Gateway.
create_tables.js
Updated the seed data for the users table to reflect the new schema (splitting name into first_name/last_name and adding validity dates).