title: Error while verifying Firebase ID token: TypeError: Cannot read property 'apply' of undefined
body: <p>I'm trying to deploy a HTTP request triggered function in Firebase Could Functions. I'm getting this error and I don't know why. The decoding of the idToken is successful</p>
  
  <pre><code>Error while verifying Firebase ID token: TypeError: Cannot read property 'apply' of undefined
      at /user_code/node_modules/express/lib/router/index.js:635:14
      at next (/user_code/node_modules/express/lib/router/index.js:260:14)
      at admin.auth.verifyIdToken.then.decodedIdToken (/user_code/index.js:24:9)
      at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  </code></pre>
  
  <p>My code is almost copy-paste from samples:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  const express = require('express');
  const cors = require('cors')({origin: true});
  const addDeviceToken = new express.Router();
  
  const dbRef = admin.database().ref();
  
  const validateFirebaseIdToken = (request, response, next) =&gt; {
      if (!request.headers.authorization || !request.headers.authorization.startsWith('Bearer ')) {
          console.error('No Firebase ID token was passed as a Bearer token in the Authorization header.',
              'Make sure you authorize your request by providing the following HTTP header:',
              'Authorization: Bearer &lt;Firebase ID Token&gt;');
          response.status(403).send("No Firebase ID token was passed as a Bearer token in the Authorization header. " +
              "Make sure you authorize your request by providing the following HTTP header: Authorization: Bearer Firebase ID Token.");
          return;
      }
  
      let idToken = request.headers.authorization.split('Bearer ')[1];
  
      admin.auth().verifyIdToken(idToken).then(decodedIdToken =&gt; {
          request.user = decodedIdToken;
          next();
      }).catch(error =&gt; {
          console.error('Error while verifying Firebase ID token:', error);
          response.status(455).send('Unauthorized');
      })
  };
  
  addDeviceToken.use(cors);
  addDeviceToken.use(validateFirebaseIdToken);
  addDeviceToken.get('/addDeviceToken', (request, response) =&gt; {
      const uid = request.query.uid;
      const token = request.query.token;
  
      console.log(token);
  
      const tokensRef = dbRef.child("/users/" + uid + "/tokens");
  
      return tokensRef.once('value').then(function (snapshot) {
          let tokens = snapshot.val();
          if (tokens === null) tokens = {};
  
          if (!(token in tokens)) {
              tokens[token] = 1;
              tokensRef.set(tokens).then(() =&gt; {
                  response.status(200).send("Token " + token + " saved.");
              });
              return;
          }
  
          response.status(200).send("The token " + token + " was already saved.");
      })
  });
  
  exports.addDeviceToken = functions.https.onRequest((req, res) =&gt; {
      if (!req.path) {
          req.url = `/${req.url}`
      }
      return addDeviceToken(req, res)
  });
  </code></pre>