Skip to content

Commit

Permalink
kommentert ut litt kode som skal brukes senere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gissebass committed Dec 23, 2023
1 parent cf2760d commit 3edd1fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import NoEncryptionGmailerrorredIcon from "@mui/icons-material/NoEncryptionGmail
import SearchIcon from "@mui/icons-material/Search";
import { useMsal } from "@azure/msal-react";
import AzureLogin from "../../views/Login/AzureLogin";
import { Person } from "@microsoft/mgt-react";

const HeaderComponent: FC = () => {
const replace = useNavigate();
Expand Down
102 changes: 51 additions & 51 deletions src/views/Login/AzureLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,57 @@ const AzureLogin: React.FC = () => {
};

//makes user if logged in user has access to do so
const createUser = async () => {
const apiUrl = "https://graph.microsoft.com/v1.0/users";
const newUser = {
accountEnabled: true,
displayName: "John Doe2",
mailNickname: "john.doe2",
userPrincipalName: "[email protected]",
passwordProfile: {
forceChangePasswordNextSignIn: true,
password: "A_Strong_Password123",
},
};

try {
const activeAccount = instance.getActiveAccount();

if (!activeAccount) {
console.error("No active account. Please log in.");
return;
}

const accessToken = await instance
.acquireTokenSilent({
account: activeAccount,
scopes: ["User.Read"],
})
.catch((error) => {
console.error("Error acquiring token silently:", error.message);
throw error;
});

if (accessToken) {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken.accessToken}`,
},
body: JSON.stringify(newUser),
});

if (response.ok) {
console.log("User created successfully");
} else {
console.error("Error creating user:", await response.text());
}
}
} catch (error: any) {
console.error("Error:", error.message);
}
};
// const createUser = async () => {
// const apiUrl = "https://graph.microsoft.com/v1.0/users";
// const newUser = {
// accountEnabled: true,
// displayName: "John Doe2",
// mailNickname: "john.doe2",
// userPrincipalName: "[email protected]",
// passwordProfile: {
// forceChangePasswordNextSignIn: true,
// password: "A_Strong_Password123",
// },
// };

// try {
// const activeAccount = instance.getActiveAccount();

// if (!activeAccount) {
// console.error("No active account. Please log in.");
// return;
// }

// const accessToken = await instance
// .acquireTokenSilent({
// account: activeAccount,
// scopes: ["User.Read"],
// })
// .catch((error) => {
// console.error("Error acquiring token silently:", error.message);
// throw error;
// });

// if (accessToken) {
// const response = await fetch(apiUrl, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${accessToken.accessToken}`,
// },
// body: JSON.stringify(newUser),
// });

// if (response.ok) {
// console.log("User created successfully");
// } else {
// console.error("Error creating user:", await response.text());
// }
// }
// } catch (error: any) {
// console.error("Error:", error.message);
// }
// };

//get function call for user profile currently logged in
useEffect(() => {
Expand Down

0 comments on commit 3edd1fe

Please sign in to comment.