Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created December 19, 2018 18:30
Show Gist options
  • Select an option

  • Save darrenmothersele/55210573beff6d2271b459b4c58974d3 to your computer and use it in GitHub Desktop.

Select an option

Save darrenmothersele/55210573beff6d2271b459b4c58974d3 to your computer and use it in GitHub Desktop.
export const getQuotaToken = functions.https.onCall(async ({ id }, context) => {
if (!context.auth) {
throw new functions.https
.HttpsError('failed-precondition', 'The function must be called while authenticated.');
}
const { uid } = context.auth;
const usage = await getUsage(uid);
const quota = context.auth.token.quota || DEFAULT_QUOTA;
const remaining = quota - usage;
const path = `${uid}/${id}`;
const token = await admin.auth().createCustomToken(uid, { remaining, path });
return { token, quota, usage, remaining };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment