Skip to content

Commit

Permalink
Update react samples to use initialize again
Browse files Browse the repository at this point in the history
  • Loading branch information
hectormmg committed Jul 21, 2023
1 parent b4c1ede commit 51a0fd3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions samples/msal-react-samples/b2c-sample/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import App from './App';
import { PublicClientApplication, EventType } from "@azure/msal-browser";
import { msalConfig } from "./authConfig";

// createPublicClientApplication asynchronously instantiates and initializes the MSAL object
PublicClientApplication.createPublicClientApplication(msalConfig).then((msalInstance) => {
export const msalInstance = new PublicClientApplication(msalConfig);

msalInstance.initialize().then(() => {
// Default to using the first account if no account is active on page load
if (!msalInstance.getActiveAccount() && msalInstance.getAllAccounts().length > 0) {
// Account selection logic is app dependent. Adjust as needed for different use cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { CustomNavigationClient } from "./utils/NavigationClient";


export default ({element}) => {
// createPublicClientApplication asynchronously instantiates and initializes the MSAL object
PublicClientApplication.createPublicClientApplication(msalConfig).then((msalInstance) => {
const msalInstance = new PublicClientApplication(msalConfig);

msalInstance.initialize().then(() => {
// The next 2 lines are optional. This is how you configure MSAL to take advantage of the router's navigate functions when MSAL redirects between pages in your app
const navigationClient = new CustomNavigationClient();
msalInstance.setNavigationClient(navigationClient);
Expand Down
6 changes: 3 additions & 3 deletions samples/msal-react-samples/nextjs-sample/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import { CustomNavigationClient } from "../src/utils/NavigationClient";
// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

// createPublicClientApplication asynchronously instantiates and initializes the MSAL object
export const msalInstance = PublicClientApplication.createPublicClientApplication(msalConfig).then((msalInstance) => {
export const msalInstance = new PublicClientApplication(msalConfig);

msalInstance.initialize().then(() => {
// Account selection logic is app dependent. Adjust as needed for different use cases.
const accounts = msalInstance.getAllAccounts();
if (accounts.length > 0) {
Expand All @@ -34,7 +35,6 @@ export const msalInstance = PublicClientApplication.createPublicClientApplicatio
msalInstance.setActiveAccount(account);
}
});
return msalInstance;
});

export default function MyApp({ Component, emotionCache = clientSideEmotionCache, pageProps }) {
Expand Down
6 changes: 3 additions & 3 deletions samples/msal-react-samples/react-router-sample/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import App from './App';
import { PublicClientApplication, EventType } from "@azure/msal-browser";
import { msalConfig } from "./authConfig";

export const msalInstance = PublicClientApplication.createPublicClientApplication(msalConfig).then((msalInstance) => {
export const msalInstance = new PublicClientApplication(msalConfig);

msalInstance.initialize().then(() => {
// Default to using the first account if no account is active on page load
if (!msalInstance.getActiveAccount() && msalInstance.getAllAccounts().length > 0) {
// Account selection logic is app dependent. Adjust as needed for different use cases.
Expand All @@ -36,6 +38,4 @@ export const msalInstance = PublicClientApplication.createPublicClientApplicatio
</ThemeProvider>
</Router>
);

return msalInstance;
});

0 comments on commit 51a0fd3

Please sign in to comment.