firebase serve: From a locally served app, call locally served functions : <blockquote>
  <p>How can I properly simulate a cloud function locally so that it has all data as when being invoked on firebase servers? (e.g. the <code>context.auth</code>)</p>
</blockquote>

<p>I am serving my project with <code>firebase serve</code>, it runs ok on <code>http://localhost:5000/</code>, however, my cloud functions are being called from <code>https://us-central1-&lt;my-app&gt;.cloudfunctions.net/getUser</code>. (The function is not even deployed.)</p>

<p>To avoid XY problem, I am trying to debug my function, but calling it from <strong>firebase shell</strong> results in <code>context.auth</code> being undefined, same when calling via <strong>postman</strong> from <code>http://localhost:5000/&lt;my-app&gt;/us-central1/getUser</code>.</p>

<p>This is my <code>./functions/src/index.ts</code> file</p>

<pre><code>import * as functions from 'firebase-functions'
import admin from 'firebase-admin'
import { inspect } from 'util'

admin.initializeApp()

export const getUser = functions.https.onCall((data, context) =&gt; {
  console.debug('== getUser called =========================================')
  console.log('getUser', inspect(data), inspect(context.auth))
  return admin.database().ref('userRights/admin').child(context.auth.uid).once('value', snapshot =&gt; {
    console.log(snapshot.val())
    if (snapshot.val() === true) {
      return 'OK'
      // return {status: 'OK'}
    } else {
      return 'NOK'
      // return {status: 'error', code: 401, message: 'Unauthorized'}
    }
  })
})
</code></pre>

<p>file <code>./firebase.functions.ts</code></p>

<pre><code>import { functions } from '~/firebase'
export const getUser = functions.httpsCallable('getUser')
</code></pre>

<p>Consumer <code>./src/pages/AdminPanel/index.tsx</code></p>

<pre><code>import { getUser } from '~/firebase.functions'
//...
getUser({myDataX: 'asd'}).then(response =&gt; console.debug('response', response))
</code></pre>
