-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
50 lines (39 loc) · 1.28 KB
/
main.js
File metadata and controls
50 lines (39 loc) · 1.28 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { PublicClientApplication } from "@azure/msal-browser";
import { msalConfig, loginRequest } from "./msalConfig.js";
const msal = new PublicClientApplication(msalConfig);
async function init() {
await msal.initialize();
const authResult = await msal.handleRedirectPromise();
if (authResult) {
show(authResult);
return;
}
const accounts = msal.getAllAccounts();
if (accounts.length > 0) {
show({ account: accounts[0], note: "restored from session cache" });
}
}
const portalSignUpUrl = new URL(
"https://mynordic.nordicsemi.com/en/sign-up/create-account",
);
portalSignUpUrl.searchParams.set("redirect_uri", msalConfig.auth.redirectUri);
function show(result) {
document.getElementById("output").textContent = JSON.stringify(
result,
null,
2,
);
document.getElementById("login").hidden = true;
document.getElementById("portal-login").hidden = true;
document.getElementById("logout").hidden = false;
}
document.getElementById("login").addEventListener("click", () => {
msal.loginRedirect(loginRequest);
});
document.getElementById("portal-login").addEventListener("click", () => {
window.location.href = portalSignUpUrl.toString();
});
document.getElementById("logout").addEventListener("click", () => {
msal.logoutRedirect();
});
init();