-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthBtn.jsx
38 lines (33 loc) · 1.06 KB
/
authBtn.jsx
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
import React from "react";
import { useMsal } from "@azure/msal-react";
import { loginRequest } from "./authConfig";
import Button from "react-bootstrap/Button";
/**
* Renders a button which, when selected, will redirect the page to the login prompt
*/
export const SignInButton = () => {
const { instance } = useMsal();
const handleLogin = (loginType) => {
if (loginType === "redirect") {
instance.loginRedirect(loginRequest).catch(e => {
console.log(e);
});
}
}
return (
<Button variant="secondary" className="ms-auto" onClick={() => handleLogin("redirect")}>Sign in</Button>
);
}
export const SignOutButton = () => {
const { instance } = useMsal();
const handleLogout = (logoutType) => {
if (logoutType === "redirect") {
instance.logoutRedirect({
postLogoutRedirectUri: "/",
});
}
}
return (
<Button variant="secondary" className="ms-auto" onClick={() => handleLogout("redirect")}>Sign out</Button>
);
}