1

I've been following the official documentation of firebase-admin for creating a custom role. I want that my user can be a doctor or a normal user only but it gives me an error:

Unhandled Runtime Error RangeError: Maximum call stack size exceeded

const functions = require("firebase-functions");

// The Firebase Admin SDK to access Firestore.
const admin = require("firebase-admin");
admin.initializeApp({
  serviceAccountId:
    "xxxxxx",
});

exports.addMessage = functions.https.onCall((data: any, context: any) => {
  const userId = "some-uid";
  const additionalClaims = {
    role: "doctor",
    name: "Juan",
  };

  admin
    .auth()
    .createCustomToken(userId, additionalClaims)
    .then((customToken: any) => {
      // Send token back to client
      console.log(customToken);
    })
    .catch((error: any) => {
      console.log("Error creating custom token:", error);
    });
});
1
  • 1
    Try adding return { data: customToken } in the .then() block ? Commented Sep 21, 2021 at 3:48

1 Answer 1

4

Dharmaraj commented on the problem: you're not returning anything from the function, which means no result is sent to the caller.

exports.addMessage = functions.https.onCall((data: any, context: any) => {
  const userId = "some-uid";
  const additionalClaims = {
    role: "doctor",
    name: "Juan",
  };

  return admin // 👈 Add return here
    .auth()
    .createCustomToken(userId, additionalClaims)
    .then((customToken: any) => {
      // Send token back to client
      return customToken;  // 👈 Add this
    })
    .catch((error: any) => {
      // Something went wrong, send error to client
      throw new functions.https.HttpsError('failed-precondition', error); // 👈 Add this
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.