title: Initialize service account and clound functions together-Firebase
body: <p>How can I initialize cloud functions and service account together. In my index.ts file I have already initialized functions using </p>
  
  <p><code>admin.initializeApp(functions.config().firebase);</code> </p>
  
  <p>but now I want to create create custom token with firebase, so I created a service account and added the <code>service-account.json</code> in my functions folder and added </p>
  
  <pre><code>const serviceAccount = require("./service-account.json");
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://functionstest-54bd9 .firebaseio.com"
  });
  </code></pre>
  
  <p>above initialize functions. but when I tried to deploy the function, i got this error in the console</p>
  
  <pre><code>Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
      at FirebaseAppError.FirebaseError [as constructor] (/home/me/Documents/TfmFirebase/functions/node_modules/firebase-admin/lib/utils/error.js:39:28)
      at FirebaseAppError.PrefixedFirebaseError [as constructor] (/home/me/Documents/TfmFirebase/functions/node_modules/firebase-admin/lib/utils/error.js:85:28)
  </code></pre>
  
  <p>I have only one app and I have added only a service account. Do I have to create another app just  to create the custom token only? How can I fix this? </p>
  
  <p><strong>Update1</strong></p>
  
  <p>This is how I am creating custom token, </p>
  
  <pre><code>//create user
  let writeResult = await db.collection('users').add({
                      user: user,
                      password: password,
                      isBlocked: false,
                      joiningDate: Date.now(),
                      phoneVerified: false,
                      deleted: false,
                      contacts:{
                          phone: phone
                      }
                  })
  
  //create token
  let tokenSnapShot = await admin.auth().createCustomToken(writeResult.id);
  const userRef = db.collection('users').doc(writeResult.id);
  let updateResult = await userRef.get();
  t.update(userRef,{ "token": updateResult.data() });
  </code></pre>
  
  <p>Please correct me if I am doing it wrong</p>