I need to access user.getIdToken() from firebase cloud functions. I am creating a user like so:
exports.addUser = functions.auth
.user()
.onCreate((user: admin.auth.UserRecord) =>
admin.auth()
.setCustomUserClaims(user.uid, {
"custom_claims": {
"USER": user.email,
"ROLE": 'SUBSCRIBER'
}
})
.then(async () => {
...
// get token
const token = user.getIdToken();
// run fetch
fetch(URL, OPTIONS_WITH_TOKEN);
Obviously user.getIdToken() does not work here, as that is a client method.
createCustomToken does not seem to be the same thing, as it does not contain all the same information (hence it is a custom token), and it adds a claims object instead of inserting the object directly.
How can I get a regular token for a header to run a fetch?
Thanks,
J