title: How to test an onCall function as an authenticated user in the functions:shell
body: <p>I want to test an onCall function via <code>firebase functions:shell</code> as an authenticated usr</p>
  
  <p>I’ve tried many of the combinations of calls from <a href="https://firebase.google.com/docs/functions/local-emulator#invoke_https_functions" rel="noreferrer">https://firebase.google.com/docs/functions/local-emulator#invoke_https_functions</a>
  As well as downloading and setting the <code>GOOGLE_APPLICATION_CREDENTIALS</code> env var</p>
  
  <p>My function looks like this:</p>
  
  <pre><code>exports.sendMessage = functions.https.onCall((data, context) =&gt; { 
      if (!context.auth) {
          throw new functions.https.HttpsError('failed-precondition', 'The function must be called while authenticated.');
      }
      // Other logic
  
  }
  </code></pre>
  
  <p>It works fine once deployed and hit from my ios app, but i can’t get it running in the shell.</p>
  
  <p>The following command will actually hit the function:</p>
  
  <p><code>sendMessage.post({headers: {'content-type' : 'application/json'},body: JSON.stringify({data: {'messageId':'test'} }) })</code></p>
  
  <p>and returns </p>
  
  <p><code>RESPONSE RECEIVED FROM FUNCTION: 400, {“error”:{“status”:“FAILED_PRECONDITION”,“message”:“The function must be called while authenticated.“}}</code></p>
  
  <p>Which is correct but I want an authenticated user now. When I try to add auth like the docs recommend: </p>
  
  <p><code>sendMessage('data', {auth:{uid:'USERUID'}}).post({headers: {'content-type' : 'application/json'},body: JSON.stringify({data: {'messageId':'test'} }) })</code> </p>
  
  <p>I end up getting <code>ERROR SENDING REQUEST: Error: no auth mechanism defined</code></p>
  
  <p>If I try following the Authorization headers on this page <a href="https://firebase.google.com/docs/functions/callable-reference" rel="noreferrer">https://firebase.google.com/docs/functions/callable-reference</a> like so: </p>
  
  <p><code>sendMessage.post({headers: {'Authorization': 'Bearer USERUID', 'content-type' : 'application/json'},body: JSON.stringify({data: {'messageId':'test'} }) })</code></p>
  
  <p>I get back:</p>
  
  <p>RESPONSE RECEIVED FROM FUNCTION: 401, {"error":{"status":"UNAUTHENTICATED","message":"Unauthenticated"}}</p>
  
  <p>How do you send the request as an authenticated user?</p>
  
  <p><strong>Related Links</strong>
  <a href="https://stackoverflow.com/questions/50884534/how-to-test-functions-https-oncall-firebase-cloud-functions-locally">How to test `functions.https.onCall` firebase cloud functions locally?</a></p>