Tuesday, 15 February 2022

Vue.js where can I get my firebaseConfig details from .

 I have the following details that need filling in on my main.js page. 

const firebaseConfig = {
apiKey: "AAAAAAAAAAAAAAAAAAAAAAA",
authDomain: "some-domain.firebaseapp.com",
projectId: "some-project",
storageBucket: "some-project.appspot.com",
messagingSenderId: "11111111111111",
appId: "1:111111111111111:web:11111111111111",
measurementId: "G-88888888"
};



Where do we get the firebaseConfig information from ? 

First off let's get the API key.   Go to your Firebase Project page https://console.firebase.google.com/projec

Next to Project overview > click on Project settings. 



The next page will have your 'Web API Key'  .  However if it says 'Not configured' then all you need to do is go into your Authentication page first and then come back to this page.  

You'll see it's filled in now :)

However to see all your details on this page.  just type in 'firebaseConfig' and all the details are there in code lower on the page.







Friday, 11 February 2022

Defining 'S3ToGCSOperator' in GCP Airflow DAG.

 I have the following operator that I want to use in this DAG.  3ToGCSOperator

transfer_data_s3_to_gcs = S3ToGCSOperator(
task_id='data_transfer_gcs_to_gcs',


However I need to define the import. 

Which is 

from airflow.providers.google.cloud.operators.s3_to_gcs import S3ToGCSOperator


What you need to do is your Environment in GCP and navigate to the ‘PYPI PACKAGES’ TAB.
And add the package https://airflow.apache.org/docs/apache-airflow-providers-google/stable/index.html

apache-airflow-providers-google

However I then got this error. 


UPDATE operation on this environment failed 5 minutes ago with the following error message:

Failed to install PyPI packages. apache-airflow-providers-google 6.3.0 has requirement google-ads<14.0.1,>=12.0.0, but you have google-ads 7.0.0.

 Check the Cloud Build log at https://console.cloud.google.com/cloud-build/builds/%%?project=4%% for details. For detailed instructions see https://cloud.google.com/composer/docs/troubleshooting-package-installatio


So what you need to do first in ‘PYPI PACKAGES’ is install oogle-ads. Version =  >=12.0.0,<14.0.1.


ModuleNotFoundError: No module named 'airflow.providers.google.cloud.operators.s3_to_gcs'

And then you'll be able to do it. 

Tuesday, 1 February 2022

Create a written date in Javascript 'moment' library.

The dates I'm outputting at the moment look like this. 



Which looks like this with 'moment' 

const written_date = moment(my_date).format('MMM d YYYY');


However, what I want is more of a fullText response. 

Moment has these name types. 

type RelativeTimeKey = 's' | 'ss' | 'm' | 'mm' | 'h' | 'hh' | 'd' | 'dd' | 'w' | 'ww' | 'M' | 'MM' | 'y' | 'yy';
type CalendarKey = 'sameDay' | 'nextDay' | 'lastDay' | 'nextWeek' | 'lastWeek' | 'sameElse' | string;
type LongDateFormatKey = 'LTS' | 'LT' | 'L' | 'LL' | 'LLL' | 'LLLL' | 'lts' | 'lt' | 'l' | 'll' | 'lll' | 'llll';


For what I wanted to achieve this works for me. 

const written_date = moment(my_date).format('ddd LL');






Wednesday, 26 January 2022

Vue.js - How to use Set VUEX values in main.js

 The answer to 'How to use Set VUEX values in main.js' is that you don't ! 


Another niche note from myself for a Google search term that I made that this blog would have save me a bit of time chasing around the houses. 


I highly recommend the YouTube video for solving this and other Vuex issues - https://www.youtube.com/watch?v=oxUyIzDbZts&t=629s


The issue I had to solve was that I'd written some code where I was using 'localStorage' when the value should be stored in VUEX .  This was being done in the main.js page. 



firebase.auth().onAuthStateChanged(async function (user) {
console.log('Auth State Checked')
if (user) {
user.getIdTokenResult().then(idTokenResult => {
if (idTokenResult.claims.admin === true) {
localStorage.adminClaim = true
}
});
}
})


The main thing here is, we can't use Vuex from the main.js page and you can't 'commit' to Vuex from here.  That will done in a VUEX 'action'.  

In store/index.js

export default new Vuex.Store({
state: {
adminRole: false,
},
mutations: {
//syncrous
setAdminRole(state, payload) {
state.adminRole = payload;
}
},
actions: {
//asyncronous
async setAdminRole(state) {
firebase.auth().onAuthStateChanged(async function (user) {
console.log('Auth State Checked')
if (user) {
user.getIdTokenResult().then(idTokenResult => {
console.log('IdTokenResult for user', idTokenResult);
console.log('idTokenResult.claims.admin',idTokenResult.claims.admin);
if (idTokenResult.claims.admin === true) {
state.commit("setAdminRole", true);
}
});
}
})
}
},
modules: {},
getters: {
getAdminRole: state => state.adminRole,
},
});


And then in App.vue we can Dispatch our 'action' like this. 

export default {
mounted(){
this.$store.dispatch("setAdminRole");
}
};


Next up is to call it in the page you want to access that data.  In our case the TopHeader page. 


Note in the video above at 8.40, he talks about timing issues.  Which is why mounted doesn’t work and we need to use computed. 



export default {
data() {
return {
},
name: "top-header",
mounted() {
},
computed: {
adminRole(){
return this.$store.getters.getAdminRole;
},
}
};


This will load a data variable 'adminRole' with our Boolean task.  So using 

{{ adminRole }}

in the template, would output either True or False. 







Tuesday, 25 January 2022

Firebase Functions Claims setting one makes my other 'claims' undefined !

In my app we have 2 roles that we need to add to the ‘claims’ .

These are

  1. Admin

  2. Coordinator

Which in my Cloud Function I set the claim to either 'true' or 'false' . Which is 'Add' and 'Remove' respectively.


However I was noticing that when setting one it was making the other claim 'undefined' . Here's what one of my functions looked like. exports.addAdminRole = functions.https.onCall((data, context) => { 3 return admin.auth().getUserByEmail(data.email).then(user => { 4 return admin.auth().setCustomUserClaims(user.uid, { 5 admin: true, 7 }); 8 }).then(() => { 10 return { 11 message: `Success! ${data.email} has been made an admin` 12 } 13 }).catch(err => { 14 return err; 15 }) 16})

To fix this issue I had to pass though instructions on what the other Roles claim should be.
I'm using Vue.js by the way. So, the other role is set in the 'data'. Which I can pick up and pass it through like this
removeAdminRole({email: this.email, coordinator_role: this.coordinator_role}).then(() => {
this.successMessage = "The admin role has been removed !";
})
And then Cloud function will look like this.
exports.addAdminRole = functions.https.onCall((data, context) => {
return admin.auth().getUserByEmail(data.email).then(user => {
return admin.auth().setCustomUserClaims(user.uid, {
admin: true,
coordinator: data.coordinator_role
});
}).then(() => {
return {
message: `Success! ${data.email} has been made an admin`
}
}).catch(err => {
return err;
})
})


This now works as it should for me.

Tuesday, 18 January 2022

Firebase Functions - Callable Function returning 'CORS' error.

firebase function has been blocked by CORS policy 


I experienced this issue while following a tutorial by The Net Ninja - Firebase Functions


function/index.js

1exports.sayHello = functions.https.onCall((data, context) => { 2 return `Yo dudes and dudettes`; 3})


DEPLOY this to Google .

And then in our button action ( fired by javascript )

1const sayHello = firebase.functions().httpsCallable('sayHello'); 2 sayHello().then(result => { 3 console.log(result.data); 4 });

 

I’d then get a CORS issue firebase function has been blocked by CORS policy

The following call to assign the region worked for me in the Google Function itself.

exports.sayHello = functions.region('us-central1').https.onCall((data, context) => {
return `Yo dudes and dudettes`;
})


Thursday, 6 January 2022

Google Data Studio ( GDS ) - Removing 'No data' from Scorecard Display

On my Scorecards where I have single values being pulled in, it is showing the text 'No data' underneath the value.  Like this. 



To remove that it's pretty simple.  Click on 'Style' on the 'Scorecard' editor. 

You then have a dropdown for 'Missing Data' 

Here select 'Show * ( blank ) ' 

That's it :)