Created
December 19, 2018 18:30
-
-
Save darrenmothersele/55210573beff6d2271b459b4c58974d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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