Skip to content

Instantly share code, notes, and snippets.

@mkiisoft
Created January 26, 2022 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkiisoft/19e3140d3fb4f86da0444666f448ddd6 to your computer and use it in GitHub Desktop.
Save mkiisoft/19e3140d3fb4f86da0444666f448ddd6 to your computer and use it in GitHub Desktop.
Firebase Cloud Function to get custom token login
const functions = require("firebase-functions");
const admin = require('firebase-admin');
const serviceAccount = require("./path-to-firebase-adminsdk.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
exports.getToken = functions.https.onCall(async (data, context) => {
return admin
.auth()
.createCustomToken(data.uid)
.then((customToken) => {
return customToken;
}).catch((error) => {
return null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment