Created
December 2, 2019 01:37
-
-
Save dalenguyen/eff80a0949cba3be1033a3e571ca17ca to your computer and use it in GitHub Desktop.
Work With Firebase Custom Claims in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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