Umar
Umar

Reputation: 261

how to apply authentication middleware with direct function calling using firebase cloud function on backend

I'm using direct function calling with firebase cloud functions and want to authenticate every functions with token for backend server

`

const functions = require('firebase-functions');
const admin = require('firebase-admin');
exports = module.exports = functions.https.onRequest((req, res) => {
    if (req.method !== 'GET') {
        return res.status(401).json({
            message: 'Method not allowed'
        })
    }
    var db = admin.firestore();
    return db.doc('channels/' + req.query.id).get()
        .then(snapshot => {
            return res.send(snapshot.data())
        })
        .catch(reason => {
            return res.send(reason)
        })
});

Please tell me how can i use auth middleware with these type of functions and correct me if going in wrong direction

Thanks in advance

Upvotes: 4

Views: 595

Answers (1)

Umar
Umar

Reputation: 261

After getting no response, i decide to go with HTTP request for function calling, with that authentications are pretty state forward, but still warm welcome good solution for my question.

Upvotes: 3

Related Questions