title: Why do my Firebase functions always have an undefined auth in the context object?
body: <p>I have this configuration in 2 different projects (Frontend + Backend) that run locally.
  I'm trying to figure out how can I use context.auth to be working automatically as it is mentioned in the documentation.</p>
  <p>So far, the only way that all this is working for me is if I do this in the backend:</p>
  <pre><code>await admin.auth().verifyIdToken(context.rawRequest.headers[&quot;x-original-auth&quot;])
  — where headers['x-original-auth'] is the Authorization Bearer Token.
  </code></pre>
  <p><strong>Client-side Initalisation</strong></p>
  <pre><code>import { initializeApp } from 'firebase/app'
  import { getFunctions, httpsCallable, connectFunctionsEmulator } from 'firebase/functions'
  import { getAuth, connectAuthEmulator, setPersistence, browserSessionPersistence } from 'firebase/auth'
  import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore'
  import { getDatabase, connectDatabaseEmulator } from 'firebase/database'
  
  export const app = initializeApp({
      projectId: &quot;default&quot;, 
      apiKey: &quot;default&quot;, 
      authDomain: &quot;localhost&quot;
  })
  
  export const functions = getFunctions(app);
  export const auth = getAuth(app);
  export const firestore = getFirestore(app);
  export const database = getDatabase(app);
  
  setPersistence(auth, browserSessionPersistence)
  
  if (process.env.NODE_ENV === 'development') {
      connectFunctionsEmulator(functions, &quot;localhost&quot;, 5001)
      connectAuthEmulator(auth, &quot;http://localhost:9099&quot;, { disableWarnings: false })
      connectFirestoreEmulator(firestore, &quot;localhost&quot;, 8080)
      connectDatabaseEmulator(database, &quot;localhost&quot;, 9000);
  }
  ...
  </code></pre>
  <p><strong>Server-side initialisation</strong></p>
  <pre><code>import * as admin from &quot;firebase-admin&quot;
  
  admin.initializeApp({projectId: &quot;default&quot;})
  
  import * as functions from &quot;firebase-functions&quot;
  
  export const functionExample = functions.https.onCall(async (data: any, context: functions.https.CallableContext) =&gt; {
  ...
  </code></pre>
  <p>and whenever I try to sign in in the frontend using any of these methods:</p>
  <pre><code>signInWithCustomToken(auth, token) — the token that I get back from the server side
  signInAnonymously(auth)
  </code></pre>
  <p>I get back the ID token, and I see that firebase handles it well on the front side:</p>
  <pre><code>Authorization: Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJwcm92aWRlcl9pZCI6ImFub255bW91cyIsImF1dGhfdGltZSI6MTYzOTE1NTIwMywidXNlcl9pZCI6IkJwUHA0eVlrS3hkRjg0SmJrTXYwcmlKandLblQiLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7fSwic2lnbl9pbl9wcm92aWRlciI6ImFub255bW91cyJ9LCJpYXQiOjE2MzkxNTUyMDMsImV4cCI6MTYzOTE1ODgwMywiYXVkIjoiZGVmYXVsdCIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9kZWZhdWx0Iiwic3ViIjoiQnBQcDR5WWtLeGRGODRKYmtNdjByaUpqd0tuVCJ9.
  </code></pre>
  <p>But my <code>context.auth</code> in the firebase is always undefined. Do you have some ideas why that could be?
  Maybe because I'm using local emulators?</p>