Created
January 26, 2022 17:53
-
-
Save mkiisoft/19e3140d3fb4f86da0444666f448ddd6 to your computer and use it in GitHub Desktop.
Firebase Cloud Function to get custom token login
This file contains 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
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