The call to the cloud function in Flutter encountered an error due to a permission issue, specifically [firebase_functions/permission-denied]

Encountering an issue while attempting to call a callable function from Flutter:

W/FirebaseContextProvider( 3655): Error retrieving App Check token. Issue: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
D/TrafficStats( 3655): tagSocket(294) with statsTag=0xffffffff, statsUid=-1
E/flutter ( 3655): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_functions/permission-denied] PERMISSION_DENIED
E/flutter ( 3655):
E/flutter ( 3655): #0      StandardMethodCodec.decodeEnvelope
message_codecs.dart:653
E/flutter ( 3655): #1      MethodChannel._invokeMethod
platform_channel.dart:315
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #2      MethodChannelHttpsCallable.call
method_channel_https_callable.dart:22
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #3      HttpsCallable.call
https_callable.dart:49
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #4      _SendFeedbackModalBottomSheetState.build.<anonymous closure>
send_feedback.dart:90
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655):
E/flutter ( 3655): #0      StandardMethodCodec.decodeEnvelope
message_codecs.dart:653
E/flutter ( 3655): #1      MethodChannel._invokeMethod
platform_channel.dart:315
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #2      MethodChannelHttpsCallable.call
method_channel_https_callable.dart:22
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #3      HttpsCallable.call
https_callable.dart:49
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #4      _SendFeedbackModalBottomSheetState.build.<anonymous closure>
send_feedback.dart:90
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655):

Below is the invocation of the callable function:

                  final HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('sendFeedback');
                  final resp = await callable.call(<String, dynamic>{
                    'email': '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c1f090f081311190e3c19041d110c1019521f1311">[email protected]</a>',
                    'message': message,
                  });

Shown here is the structure of the cloud function:

const sendgridApiKey = functions.config().sendgrid.key;
sgMail.setApiKey(sendgridApiKey);
export const sendFeedback = functions.https.onCall(async (data, context) => {
  // Verify user authentication
  if (!context.auth) {
    throw new functions.https.HttpsError("unauthenticated", "User is not authenticated");
  }

  const message = data.message;

  try {
    // Create email message
    const emailMessage = {
      to: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba3aea7a7a48baeb3aaa6bba7aee5a8a4a6">[email protected]</a>",
      from: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="056b6a28776075697c45607d64687569602b666a68">[email protected]</a>",
      subject: "Feedback from user",
      text: message,
    };

    // Utilize SendGrid to send email
    await sgMail.send(emailMessage);

    return {
      success: true, message: "Email sent successfully",
    };
  } catch (error) {
    console.error("Error sending email:", error);
    throw new functions.https.HttpsError("internal", "An error occurred while sending the email");
  }
});

This problem occurs on both the emulator and physical device. Ensured that the service account "App Engine default service account" has been assigned the role of "Editor". Is there something I am overlooking to resolve this permission issue?

Update: Attempted to employ the App Check debug token as suggested at https://firebase.google.com/docs/app-check/flutter/debug-provider#android and no longer facing the error "Error getting App Check token. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed". However, the permission denied error persists.

Answer №1

After implementing the necessary changes, I was able to successfully troubleshoot the issue by including the Cloud Functions Invoker role for the function's permissions and granting access to the allUsers principal.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Example of Using Bluebird in a Chain of Catch and Then Functions

I am struggling to understand how promises work in my code flow setup. I want to create a register function with multiple steps, but I'm unsure of what is achievable and what is not. Imagine I have a register function where I need to: register a u ...

Changing a d3 event from JavaScript to Typescript in an Angular2 environment

I am a beginner in Typescript and Angular 2. My goal is to create an Angular2 component that incorporates a d3js tool click here. However, I am facing challenges when it comes to converting it to Typescript. For instance, I am unsure if this code rewrite ...

Google Chrome does not support inlined sources when it comes to source maps

Greetings to all who venture across the vast expanse of the internet! I am currently delving into the realm of typescript-code and transcending it into javascript. With the utilization of both --inlineSourceMap and --inlineSources flags, I have observed t ...

Is there a way to fetch all users from the Firebase database excluding the current user?

Currently, I am utilizing a Recycler view to fetch all users from Firebase. Here is the code snippet: @Override public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ...

What is the best way to define a typescript interface as a class property?

Here is an example of how I have defined an interface: export interface Donor{ donorName: string; donorId: string; donorPassword:string donorAge: number fitnessReport: string physicianApproval: string } In the following class, I w ...

Guide on integrating snackbar into a function within Angular 7

I currently have a mat-table with 6 columns. The 5th column displays the status of the job, which can be Completed, Running, or Pending. I've added two buttons - Stop and Re-Run. When a user clicks on the Stop button, I want the job to stop executing ...

The performance of web API calls on an Angular 7 app deteriorates gradually with each subsequent call

My Angular application in C# is experiencing a slowdown when making calls to the web API and executing a stored procedure. While the C# code performs quickly, the 'Content Download' process is progressively slowing down with each call. https://i ...

Cannot utilize the subscribed output value within the filter function

I am in need of assistance with my Angular 7 project. I have successfully implemented a service to call a Json file and output an object array. However, I am facing an issue when trying to filter the objects in the array based on a specific property called ...

Issue: Prior to initiating a Saga, it is imperative to attach the Saga middleware to the Store using applyMiddleware function

I created a basic counter app and attempted to enhance it by adding a saga middleware to log actions. Although the structure of the app is simple, I believe it has a nice organizational layout. However, upon adding the middleware, an error occurred: redu ...

Ionic4: the functionality of the searchbar results is not functioning correctly

I have integrated the ion-searchbar in my application to filter a list of customers based on their first name and/or last name. However, I am facing two major challenges: Challenge 1: The search bar currently only matches either the first name OR the last ...

Angular - developing a custom web element to enhance the project

Is there a way to convert a single module into a web component and integrate it within the same project? Specifically, I have 3 modules in my project and I am looking to transform only module1 into a web component and incorporate it seamlessly. Thank you! ...

Is it considered poor practice in TypeScript to manually set the type when the type inference is already accurate?

Is it necessary to explicitly set the variable type in TypeScript when it is inferred correctly? For example: const add = (a: number, b: number) => a + b; const result = add(2, 3); // Or should I explicitly declare the return value type? const add = ...

A step-by-step guide on setting up a database connection with .env in typeorm

I encountered an issue while attempting to establish a connection with the database using ormconfig.js and configuring .env files. The error message I received was: Error: connect ECONNREFUSED 127.0.0.1:3000 at TCPConnectWrap.afterConnect [as oncomplete] ( ...

"Flutter runs smoothly on Android Emulator, but having difficulty getting it to work on iOS Simulator

(OK) Successfully ran the project on VS Code or Android Studio with the Android emulator without any issues. (OK) Ran Runner.xworkspace on iOS Simulator and it worked perfectly. (Failed) Attempted to run flutter with iOS Simulator, but encountered fail ...

Interactive checkboxes with data entry fields

Is there a way to achieve the following design? I need to place a textfield next to the last checkbox, but right now, the last checkbox is not aligned with the rest. Does anyone have an idea on how to make this possible? Would using CSS solve the issue? T ...

Creating personalized directives

Seeking help on Vue's custom directives with Typescript integration. Despite extensive search online and in chat rooms, I am unable to find any solutions. <button v-clickOutside="myFunc"> Click Outside </button> Implementing the ...

What is the purpose of `{ _?:never }` in programming?

I've been going through some TypeScript code and I stumbled upon a question. In the following snippet: type LiteralUnion<T extends U, U extends Primitive> = | T | (U & { _?: never }); Can anyone explain what LiteralUnion does and clarif ...

What is causing the malfunction in this overloaded function signature?

Encountering an issue when attempting to declare an overloading function type with a full type signature in TypeScript. For example: // Full type signatures for functions type CreateElement = { (tag : 'a') : HTMLAnchorElement, (tag ...

Exploring the world of mocking tests using Jest and inputs

Is there a way to create a jest test specifically for this function? const input = require('prompt-sync')(); export function choices(): void { const choice = input("Choose a letter"); if (choice === "a") { con ...

Component that wraps around children elements and passes props to their render function

I'm currently working on coding a wrapper component that takes a title prop and a children prop which must be a function. All the other props passed to the wrapper should be used as arguments when rendering the children: import React, { ReactNode, Inp ...