Created
November 4, 2018 05:40
-
-
Save ArtiomLK/25a86fd8f1940e5031df284735dde2ba to your computer and use it in GitHub Desktop.
Generated a Custom Token from the Cloud Functions for Firebase
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
import * as functions from 'firebase-functions'; | |
import * as admin from "firebase-admin"; | |
// Start writing Firebase Functions | |
// https://firebase.google.com/docs/functions/typescript | |
export const getCustomToken = functions.https.onRequest((request, response) => { | |
if (admin.apps.length < 1) { //Checks if app already initialized | |
admin.initializeApp(); | |
} | |
const uid = "USER_UUID"; //e.g. GVvCdXAC1FeC4WYTefcHD8So3q41 | |
admin.auth().createCustomToken(uid) | |
.then(function(customToken) { | |
console.log(customToken.toString); | |
response.send(customToken); | |
}) | |
.catch(function(error) { | |
console.log("Error creating custom token:", error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment