Posts

Firebase Storage Make only Selected Basket (Folder) Public

Image
 One of the big issue I face with google cloud storage is when I go to build a site which has public as well as private sections. Defult rule  as follows make the whole basket open to read which is not necessary.  match /{allPaths=**} {       allow read;       allow write: if request.auth != null;     } If you make a basket (generated)  base rule and try to access the file without token like below , it will gives permission issue . https://firebasestorage.googleapis.com/v0/b/<project id>.appspot.com/o/generated%test_400*400.png?alt=media&token= {   "error": {     "code": 403,     "message": "Permission denied. Could not perform this operation"   } } The issue have to resolve in google cloud storate admin by giving access to perticular basket. Ref : https://cloud.google.com/storage/docs/access-control/making-data-public#objects Go to following URL : https://console.cloud.google.com/storage/browser?pr

Firebase Storage ApiError: Forbidden #299 ... ApiError: Forbidden at new util

Image
When, I want to utise firebstore for the frist time in the google cloud functions,  the main problem I had to face it the integration issue raise as follows.  The google firebase and the google cloud storage eveloved seperately and in order to use the clould storage in firebase functions, the special autherntication need to be grantted even you are using firebase admin sdk. ApiError: Forbidden at new util.ApiError (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:107:10) at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:149:33) I implemeted the firebase admin sdk as follows. const firebaseAdmin = require("firebase-admin"); firebaseAdmin.initializeApp(functions.config().firebase); And firebase cloud bucket implemented  as follows . const storageRoot = firebaseAdmin.storage().bucket() Google document also indicate authentication req

Homebrew Install Mysql and Connect to Workbentch

Install MySql in MacOS Seirra can be done as follows. brew install mysql brew services start mysql mysqladmin -u root password 'newpassword' Login ; mysql -u root -p  Get Config Location : mysql --help | grep cnf Config Path :  export MYSQL_PATH=/usr/local/Cellar/mysql/8.0.12  PATH=$MYSQL_PATH/bin:$PATH Connect Squrel if you filed to collect  with mysql as follows :   MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found https://stackoverflow.com/questions/51179516/sequel-pro-and-mysql-connection-failed Go to my.cnf file and in section   [mysqld]   add line: default-authentication-plugin=mysql_native_password . Then, login to mysql server from terminal and run   mysql -u root -p , then inside shell execute this command:   ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>'; exit f

Migrate to php7 in Mac os Sierra with Apache Configurations

Image
Mac os Sierra defult comes with Apache as well as php 5.. Fi you want to start apache with defult settings The following articles gives short as well as comprehesive guideline. https://jason.pureconcepts.net/2016/09/install-apache-php-mysql-mac-os-x-sierra/ https://medium.com/@JohnFoderaro/how-to-set-up-apache-in-macos-sierra-10-12-bca5a5dfffba However , I wanted to setup firebase integration with laravel and it requires php 7. ( kreait/firebase-php ^ 4.0 ) You can eassy install php 7 using homebrew. brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/homebrew-php brew unlink php56 brew install php70 Thin you can check the version as follows . $ php --version But if you have enabled defult php in Mac Os , you will see  it will return 5.6 In order to chanage this you have to edit the httpd.conf file of apache.  Stop apache -    sudo apachectl stop move to etc/ apache2. -    cd /etc/apache2 backup httpd.conf.   - sudo cp httpd.conf httpd.conf.er

Firebase Cloud Functions Triggers with Two varibles

Image
 Although firebase functions document not mentioned about how many varible values can be exhist in firebase onWrite() tirgger , I have used it upto 2 levles without any issue.  For an exaplen in the blow code , I have consider the change in list under the userId ,, The value will be wrriten under the varible of user.  exports.testFunctionName = functions.database.ref('/user-list/{user}/{pushId}').onWrite(( change,context) => {             const original =  change.after.val();             var pushId=context.params.pushId;                 var userId=context.params.user; ...

Covert firebase to Node Express Rest API

Image
 Firbase hosting and functions provide nice solution to develop a REST api .The following video from firebase provide more infromation than our simple REST API. https://www.youtube.com/watch?v=LOeioOKUKI8 I thought of detail the process  in to more depth. First , you need to go to desired folder and install firebase tools. You should have npm for do that. Then create a firebase account and project with desired name. After that, you have to use the command firebase init. The online authentication will be proceed there after .You have to copy and paste the URL displayed in the console to the web browser. Then there we have to create the local project with firebase hosting and firebase functions. In the project you can see the functions folder ,which used to create the functions. In order to use the express, you need to use express npm packge. Move to functions folder and then run npm install express, then firebase-functions. If you are using firebase database , you

How to user firebase Orderby Wisely

Image
There are number of ways  firebase order by can be used.Ferfer the following example.  It can be user as a where clause  to select values based on child attribute.You dont need to select items within the for loop.  todoRef.orderByChild("title").equalTo("test 1").once('value').then(function(snapshot) {     snapshot.forEach(function(childSnapshot) {         var todoID=childSnapshot.key; }) }).. We can use it as fallow,,