Home > Software design >  TypeError: performanceMeasurement.startMeasurement is not a function
TypeError: performanceMeasurement.startMeasurement is not a function

Time:01-19

Error simply occured when trying to hit login from @azure/msal-react in Next 13. When I checked the error log, it's coming from core library @azure/msal-react. I also tried with login popup, but the error still same

I have code, in my auth.ts

export const msalConfig = {
    auth: {
        clientId : "afxxxxx-xxxxxx-xxxxxx",
        authority : "https://login.microsoftonline.com/common/",
        redirectUri : "/",
    }
};

export const loginRequest = {
    scope: ["User.Read"]
};

_app.ts

import { MsalProvider } from '@azure/msal-react'
import { PublicClientApplication, EventType, SilentRequest, AccountInfo } from '@azure/msal-browser'
import  { msalConfig } from '@/services/auth'
import type { AppProps } from 'next/app'
import { useRouter } from 'next/router'
import { CustomNavigationClient } from '@/utils/NavigationClient'

export const msalInstance = new PublicClientApplication(msalConfig);

const accounts = msalInstance.getAllAccounts();

if (accounts.length > 0) {
  msalInstance.setActiveAccount(accounts[0]);
};

msalInstance.addEventCallback((event) => {
  if (event.eventType === EventType.LOGIN_SUCCESS && (event.payload as SilentRequest).account) {
    const account  = (event.payload as SilentRequest).account;

    msalInstance.setActiveAccount(account as AccountInfo);
  }
});

export default function App({ Component, pageProps }: AppProps) {
  const router = useRouter();

  const navigationClient = new CustomNavigationClient(router);;

  msalInstance.setNavigationClient(navigationClient);  

  return (
    <MsalProvider instance={msalInstance}>
      <Component {...pageProps} />
    </MsalProvider>
  )
}

and in my pages just simply show Login Index.ts

const initializeSignIn = () => {
    instance.loginRedirect();
  };

  return (
  <>
    <UnauthenticatedTemplate>
      <center>Please sign-in to see your profile information.</center>
      <button onClick={initializeSignIn}>Sign In</button>
    </UnauthenticatedTemplate>
  </>
  )

Did I miss something in configuration or it is just a bug from core library?

CodePudding user response:

I came along this issue also today. This propably has something to do that microsoft released a new version. I just downgraded and it worked again.

CodePudding user response:

At the time of this issue, the last published versions are

"@azure/msal-browser": "2.32.2",
"@azure/msal-react": "1.5.2"

I've used the microsoft-authentication-library-for-js to get @azure/msal-browser, @azure/msal-react to run my project using the source code. Worked fine. It seems the problem occurred when the code was published (bundling/ minification/ who knows etc.).

until the new release comes out, to solve the issue, change the npm packages to

"@azure/msal-browser": "~2.32.1",
"@azure/msal-react": "~1.5.1"
  • Related