No authentication methods were specified

I am receiving this error ‘No authentication methods were specified’ even though I have enable the custom auth function in Authentication, also in Endpoint function settings I can see the App Auth is select in Authentication options.

In the API flow custom function should work as middleware and check if the user exists using Microsoft graph API, if true allow or else not, more the token is passing with the API headers as Authorization key.

Custom Auth Func code:

exports = async function (payload, request) {

  try {
    // Make the HTTP GET request to the Microsoft Graph API
    const response = await context.http.get({
      url: 'https://graph.microsoft.com/v1.0/me',
      headers: {
        Authorization: ['Bearer ' + request.headers["Authorization"]],
        'Content-Type': ['application/json'],
      },
    });

    // Check the response status code
    if (response.statusCode === 200) {
      const body = EJSON.parse(response.body.text());
      return body.id;
    } else {
      throw new Error('Failed to retrieve user information from the Microsoft Graph API.');
    }
  } catch (error) {
    console.error(error);
    return { error: error.message };
  }
};