Linkedin sign in not working, errors sgugest that the library is not fully loaded

So I have this javascript code:

$(document).ready(function () {
    $("#login_with_linkedin").on("click", requestAuthLinkedIn);
    googleInit();
    LinkedInInit();
});

function LinkedInInit() {
    $.getScript("https://platform.linkedin.com/in.js", function () {
        IN.init({
            api_key: MY_API_KEY,
            authorize: true,
            onLoad: function () {
                IN.Event.on(IN, "auth", function () {
                    onLinkedInAuth();
                });
            },
            scope: "r_basicprofile r_emailaddress openid email profile"
        });
    });
}

function onLinkedInAuth() {
    IN.API.Profile("me").result(function (data) {
        var profile = data.values[0];
        console.log(profile);
    });
}

function requestAuthLinkedIn() {
    IN.User.authorize();
}

This would be the frontend part:

<div id="loginLinkedIn" runat="server" visible="false">
    <div id="login_with_linkedin">
        <img src="<%= ComunControls.Global.URL_Resources %>i/login/LinkedIn_SignIn.png" alt="" />
    </div>
</div>

The problem is that when I click on the linkedin “button”(image), I keep gettint this error in the javascript console

Uncaught TypeError: Cannot read properties of
undefined (reading ‘then’)
at Object.authorize (in.js?_=1676306000491:25:68028)
at HTMLDivElement.requestAuthLinkedIn (:38:13)
at HTMLDivElement.dispatch (com_5jq.min.js?v=382:2:68763)
at a.handle (com_5jq.min.js?v=382:2:66808)

If I’m not mistaken, the linkedin JS is fully loaded when I try to trigger the event, so I don’t really know what I’m doing wrong