forked from Azure-Samples/Java-AI-Based-Content-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (33 loc) · 1.17 KB
/
index.js
File metadata and controls
36 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import {EventType, PublicClientApplication} from "@azure/msal-browser";
import {msalConfig} from "./authConfig";
import {HashRouter} from "react-router-dom";
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) {
msalInstance.setActiveAccount(accounts[0]);
}
msalInstance.addEventCallback((event) => {
if (event.eventType === EventType.LOGIN_SUCCESS && event.payload) {
const payload = event.payload;
const account = payload.account;
msalInstance.setActiveAccount(account);
}
});
const root = ReactDOM.createRoot(
document.getElementById("root")
);
root.render(
<HashRouter>
<App pca={msalInstance} />
</HashRouter>
);
}).catch((error) => {
console.error('MSAL initialization failed:', error);
msalInstance.clearCache();
});