I seem to be having issues getting my site live onto the Firebase Hosting.
I followed this tutorial: https://github.com/firebase/functions-samples/tree/master/stripe
Which has these steps:
Create a Firebase Project using the Firebase Developer Console
Enable billing on your project by switching to the Blaze or Flame plan. See pricing for more details. This is required to be able to do requests to non-Google services.
Enable Google sign on your Firebase project
Install Firebase CLI Tools if you have not already and log in with firebase login.
RESULT: Already logged in as user#gmail.com
Configure this sample to use your project using firebase use --add and select your project.
RESULT: Error: Firebase use must be run from a Firebase Directory
Run firebase init to start a project
Run firebase init
What Firebase CLI features do you want to setup for this directory?
Database
Functions
Hosting
I chose HOSTING.
Select a default Firebase project for this directory
I Chose the only project there and got:
✔ Firebase initialization complete
I Ran Firebase use --add again, chose and alias and not it says:
Now using alias stageTemp.
Install dependencies locally by running: cd functions; npm install; cd -
npm WARN stripe-functions# No repository field
npm WARN stripe-functions# No license field.
Add your Stripe API Secret Key to firebase config: firebase functions:config:set stripe.token=<YOUR STRIPE API KEY>
Optional: change your default currency firebase functions:config:set stripe.currency=GBP
Pass your Stripe publishable key to the Stripe.setPublishableKey call in public/index.html
Deploy your project using firebase deploy
When I run Firebase Deploy I get
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
✔ runtimeconfig: all necessary APIs are enabled
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (2.91 KB) for uploading
✔ functions: functions folder uploaded successfully
i starting release process (may take several minutes)...
i functions: updating function createStripeCharge...
i functions: updating function createStripeCustomer...
i functions: updating function addPaymentSource...
i functions: updating function cleanupUser...
✔ functions[createStripeCharge]: Successful update operation.
✔ functions[createStripeCustomer]: Successful update operation.
✔ functions[addPaymentSource]: Successful update operation.
✔ functions[cleanupUser]: Successful update operation.
✔ functions: all functions deployed successfully!
✔ Deploy complete!
Finally:
Test your Stripe integration by viewing your deployed site firebase open hosting:site
and then I get this:
Can anyone see why this is not working? I have gone through these steps several times and cannot seem to get it to work.
Much appreciated.
Questions for Firebase Devs:
1) This code on the example has: amount: parseInt(). What checks are in place to make sure that the DOM is not simply edited by the user?
2) This process saves a lot of data. Is Firebase PCI Compliant so that I am legally allowed to store this data?
3) I'm confused about the process flow of functions. Is there an editable file that is run on the cloud where I can add extra information and database interactions or email sending? - I ask this because I want to insert into the database only when payment is verified. If I code it from the front end then a user could just run that in the console or wherever and insert into my db as it will have write access. (I hope this makes sense - I basically just want my function to be able to access the database and not anyone else)
Thank you for your time, I understand that you will be terrible busy and I really appreciate your help with this.
Related
Following the Firebase examples to create and deploy a function, I keep failing at the deploy phase.
The error, with --debug enabled, shows:
<<< [apiv2][body] POST
https://cloudfunctions.googleapis.com/v1/projects/actus-poc2/locations/us-central1/functions
{"error":{"code":403,"message":"Cloud Functions uses Artifact Registry
to store function docker images. Artifact Registry API is not enabled
in your project. To enable the API, visit
https://console.developers.google.com/apis/api/artifactregistry.googleapis.com/overview?project=...
Now I was expecting to be able to stay within the confines of the firebase console but this message seems to imply I need to open the Google Cloud Console to enable additional permissions.
Should the code samples better document this?
Or is this a recent change in firebase functions that breaks many of the existing examples?
I need to open the Google Cloud Console to enable additional permissions.
The reason why you need to use the Google Cloud Console is because Cloud Functions for Firebase relies on some Google Cloud services. See.
Function deployments with Firebase CLI 11.2.0 and higher rely on Cloud Build and Artifact Registry.
is this a recent change in firebase functions that breaks many of the existing examples?
Deployments to older versions also do rely on some Google Cloud services. Deployments to older versions use Cloud Build in the same way, but rely on Container Registry and Cloud Storage for storage instead of Artifact Registry.
Should the code samples better document this?
If you do think an update to said documentation could be helpful, here is more about opening Feature requests.
On a Vue app I enabled firebase functions to send messages from contact form.
I do not want to use functions anymore, but only hosting and firestore.
I have removed the function from index.js in functions folder, but when I do firebase deploy I get:
Error: Your project must be on the Blaze (pay-as-you-go)
plan to complete this command. Required API cloudbuild.googleapis.com
can't be enabled until the upgrade is complete.
This happened after upgrading to node 10, and it's the reason I don't want to use functions anymore.
How do I remove functions completely from project?
I was able to deploy after upgrading by removing:
"functions": {
"source": "functions"
}
in firebase.json. Optionally I also removed functions folder.
You can simply delete all the functions manually in the Firebase console.
Or, you can downgrade back to node 8 and redeploy an empty index.js to delete the functions. You will need to use a version of the CLI less than version 9.0.0.
When I run the command "firebase deploy --only functions" it takes around 1 minute to deploy my function even if I didn't update my function.
Am I doing something wrong?
Could it be because of the node_modules folder in my functions folder?
Is function deployment in firebase just slow?
Console Log:
C:\Users\myUser\Desktop\myProject> firebase deploy --only functions
=== Deploying to 'myProject'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (36.96 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating Node.js 10 (Beta) function myFunction(europe-west1)...
i scheduler: ensuring necessary APIs are enabled...
i pubsub: ensuring necessary APIs are enabled...
+ scheduler: all necessary APIs are enabled
+ pubsub: all necessary APIs are enabled
i functions: scheduler job firebase-schedule-myFunction-europe-west1 is up to date, no changes required
+ functions[myFunction(europe-west1)]: Successful update operation.
+ Deploy complete!
It usually gets stuck for 1 minute on this line:
i functions: scheduler job firebase-schedule-svt-europe-west1 is up to date, no changes required
1-2 minutes is typical. Unlike some other FaaS providers, Cloud Functions is actually running npm install and building the node_modules in the cloud, which does take some time but also means you don't need to worry about cross-compiling native dependencies.
Cloud Functions doesn't know if you updated your function or not, so it does a fresh redeploy every time.
My recommendation is to ONLY update the functions you changed. You can do this with the following:
firebase deploy --only functions:specificFunctionName,functions:anotherFunctionName,etc
This should speed things up at least a little bit, but probably not a lot.
When I try to run `Firebase deploy', it stucks at this line of code
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
the firebase init and firebase login are doing fine but firebase deploy keeps stuck. My firebase version is 3.18.4 and im currently using ubuntu 17.10.
EDIT:
and after waiting for about an hour it diplays this line of code
FIREBASE WARNING: auth() was canceled: Auth token is expired.
Am I doing something wrong?. I am new to Firebase and I need some tips/ advice on why this happening
Here is a tip, that might help you. Give it a try and tell me if it resolves your issue.
Always use these commands instead of just firebase deploy
firebase deploy --only hosting
firebase deploy --only functions <<- use this in ur case. Also make sure your in the directory /functions of your project where you ran your firebase init
Sometimes Firebase services may be down, which would prevent you from deploying your code. If you can't deploy, check this site and see if at least all services are up and running: https://status.firebase.google.com/
Whenever I use following command in terminal (mac os sierra)
firebase init
below three option will be displayed
❯◯ Database: Deploy Firebase Realtime Database Rules
◯ Functions: Configure and deploy Cloud Functions
◯ Hosting: Configure and deploy Firebase Hosting sites
If I select nothing and press Enter
I will get below message
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
i .firebaserc already has a default project, skipping
i Writing configuration info to firebase.json...
i Writing project information to .firebaserc...
✔ Firebase initialization complete!
But when I select second option
◯ Functions: Configure and deploy Cloud Functions
I will get below message
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
i .firebaserc already has a default project, skipping
=== Functions Setup
A functions directory will be created in your project with a Node.js
package pre-configured. Functions can be deployed with firebase deploy.
Error: HTTP Error: 401, The entered credentials were incorrect.
Amits-MacBook-Pro:firebase-functions Amit$
I have tried with firebase logout and then firebase login again but same error is coming
I have also used firebase list
I got below warning and then I got list of project
Amits-MacBook-Pro:firebase-functions Amit$ firebase list
Warning: advanced compression encodings unavailable without ES6/C++11. Falling back to gzip.
Since long time ago I have used firebase function with another google login, now I am logout from that and started to login with different google login account but unable to do it, if I login with previouse google login still it's not working
I have also check directory where I have used firebase init no files are creating in that directory.
In demo of Firebase function they have shown that some files are created
https://www.youtube.com/watch?v=EvV9Vk9iOCQ&t=308s
Should I uninstall firebase and install it again? if yes, just let me know how to uninstall?
I had the same Firebase Error: "HTTP Error: 401, The entered credentials were incorrect" when I was authenticated with the wrong Google account.
I did firebase login --reauth and logged in with the right account.
After that, the project was successfully deployed.