Skip to content

Instantly share code, notes, and snippets.

@ArtiomLK
Created November 4, 2018 05:40
Show Gist options
  • Save ArtiomLK/25a86fd8f1940e5031df284735dde2ba to your computer and use it in GitHub Desktop.
Save ArtiomLK/25a86fd8f1940e5031df284735dde2ba to your computer and use it in GitHub Desktop.
Generated a Custom Token from the Cloud Functions for Firebase
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