Skip to content

Instantly share code, notes, and snippets.

@dalenguyen
Created December 2, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalenguyen/eff80a0949cba3be1033a3e571ca17ca to your computer and use it in GitHub Desktop.
Save dalenguyen/eff80a0949cba3be1033a3e571ca17ca to your computer and use it in GitHub Desktop.
Work With Firebase Custom Claims in WordPress
// https://gist.github.com/dalenguyen/650ab896086f3213e81eda5e96efe3d3
(function ($) {
'use strict';
$(document).ready(function () {
const showFirestoreDatabase = () => {
...
}
// We won't call the function directly here
// showFirestoreDatabase()
const getUserCustomClaims = () => {
firebase.auth().onAuthStateChanged(function (user) {
firebase.auth().currentUser.getIdTokenResult()
.then((idTokenResult) => {
// Confirm the user is an Admin.
if (!!idTokenResult.claims.admin) {
// We will call the function here
showFirestoreDatabase()
} else {
// Show something else
}
})
.catch((error) => {
console.log(error);
});
});
}
getUserCustomClaims()
})
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment