Created
May 9, 2022 02:18
-
-
Save antonkrasov/14ee18bf4f51bd70fa0612423791c863 to your computer and use it in GitHub Desktop.
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 serviceAccount = require("./service-account.json"); | |
const { initializeApp, cert } = require('firebase-admin/app'); | |
const { getAuth } = require('firebase-admin/auth'); | |
const app = initializeApp({ | |
credential: cert(serviceAccount) | |
}) | |
const auth = getAuth(app) | |
exports.protectedEndpoint = functions.https.onRequest(async (request, response) => { | |
try { | |
const xApiToken = request.headers['x-api-token'] | |
const decodedToken = await auth.verifyIdToken(xApiToken) | |
response.send({ decodedToken }); | |
} catch (ex) { | |
response.status(403).json({ | |
error: "'x-api-token' header is required!" | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment