Hello @Jakub Husařík
One thing to check is whether the client ID you are using to obtain the AAD token is the same as the one you registered in the Azure Function app.
Make sure that the client ID you are using in the getClient
method matches the client ID of the Azure AD app registration you created for the Azure Function app.
Another thing to check is whether the user account you are using to authenticate has the necessary permissions to call the Azure Function. Make sure that the user account you are using has been granted the necessary permissions to call the Azure Function app.
If you have checked these things and are still encountering issues, you may want to try using Fiddler or another HTTP debugging tool to see the exact request and response being sent between your SPFX web part and the Azure Function app. This can help you identify any issues with the request or response that may be causing the 401 Unauthorized error.
I hope this helps