Help with Cloud Function and pathToMyPrivateKeyFile



Following the docs at

const functions = require(“firebase-functions”);
const jwt = require(‘jsonwebtoken’);
const fs = require(‘fs’);
const key = fs.readFileSync(’pathToMyPrivateKeyFile’);
exports.myAuthFunction = functions.https.onCall((data, context) => {
const uid = context.auth.uid,
const payload = { userId: uid },
const token = jwt.sign(payload, { key: key, passphrase: “your-passphrase” }, { algorithm: ‘RS256’}),
return { token:token }

I’m looking for documentation around ‘pathToMyPrivateKeyFile’. I’ve generated the public/private keys, enabled JWT for my project on the Realm Platform Dashboard, but could use some guidance with the private key path and getting the private key on my project instance server…


Did you ever figure this out? I have the same question.


You deployed the pem file, along with the function, to Firebase - right?


I’ve copied the pem format of the public key to the Realm console and enabled JWT. So far, so good.

The Firebase Cloud Function code has this line:

const key = fs.readFileSync(’pathToMyPrivateKeyFile’);

The private key file is on my computer. I don’t have my own server. I assume I have to copy the file to Firebase (using Firebase Storage?) and then get a path to the file. The instructions are lacking about this.


OK, I figured this out. For the next poor soul who doesn’t regularly write node js stuff, do this:

  1. Copy your private key file to the functions directory in your cloud functions project
  2. Replace
    const key = fs.readFileSync(’pathToMyPrivateKeyFile’);
    const key = fs.readFileSync(path.resolve(__dirname, “myPrivateKeyFilename”));