Skip to content

Commit

Permalink
Replace createPublicClientApplication in TS react sample with instant…
Browse files Browse the repository at this point in the history
…iation + initialize
  • Loading branch information
hectormmg committed Jul 21, 2023
1 parent 51a0fd3 commit 724846c
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions samples/msal-react-samples/typescript-sample/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ import {
} from "@azure/msal-browser";
import { msalConfig } from "./authConfig";

export const msalInstance =
await PublicClientApplication.createPublicClientApplication(msalConfig);
export const msalInstance = new PublicClientApplication(msalConfig);

// Account selection logic is app dependent. Adjust as needed for different use cases.
const accounts = msalInstance.getAllAccounts();
if (accounts.length > 0) {
msalInstance.setActiveAccount(accounts[0]);
}

msalInstance.addEventCallback((event: EventMessage) => {
if (event.eventType === EventType.LOGIN_SUCCESS && event.payload) {
const payload = event.payload as AuthenticationResult;
const account = payload.account;
msalInstance.setActiveAccount(account);
msalInstance.initialize().then(() => {
// Account selection logic is app dependent. Adjust as needed for different use cases.
const accounts = msalInstance.getAllAccounts();
if (accounts.length > 0) {
msalInstance.setActiveAccount(accounts[0]);
}
});

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<Router>
<ThemeProvider theme={theme}>
<App pca={msalInstance} />
</ThemeProvider>
</Router>
);
msalInstance.addEventCallback((event: EventMessage) => {
if (event.eventType === EventType.LOGIN_SUCCESS && event.payload) {
const payload = event.payload as AuthenticationResult;
const account = payload.account;
msalInstance.setActiveAccount(account);
}
});

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<Router>
<ThemeProvider theme={theme}>
<App pca={msalInstance} />
</ThemeProvider>
</Router>
);
});

0 comments on commit 724846c

Please sign in to comment.