Skip to content

Commit e21e9b1

Browse files
committed
update-steps
1 parent e37ccc3 commit e21e9b1

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

articles/active-directory/develop/tutorial-single-page-app-react-call-api.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: active-directory
88
ms.subservice: develop
99
ms.author: owenrichards
1010
ms.topic: tutorial
11-
ms.date: 11/28/2022
11+
ms.date: 09/25/2023
1212
#Customer intent: As a React developer, I want to know how to create a user interface and access the Microsoft Graph API
1313
---
1414

@@ -37,40 +37,41 @@ To allow the SPA to request access to Microsoft Graph, a reference to the `graph
3737

3838
:::code language="javascript" source="~/ms-identity-docs-code-javascript/react-spa/src/graph.js" :::
3939

40-
## Change filename and add required imports
40+
## Update imports to use components in the application
4141

42-
By default, the application runs via a JavaScript file called *App.js*. It needs to be changed to *App.jsx* file, which is an extension that allows a developer to write HTML in React.
42+
The following code snippet imports the UI components that were created previously to the application. It also imports the required components from the `@azure/msal-react` package. These components will be used to render the user interface and call the API.
4343

4444
1. In the *src* folder, open *App.jsx* and replace the contents of the file with the following code snippet to request access.
4545

4646
```javascript
47-
import React, { useState } from 'react';
48-
49-
import { PageLayout } from './components/PageLayout';
50-
import { loginRequest } from './authConfig';
51-
import { callMsGraph } from './graph';
52-
import { ProfileData } from './components/ProfileData';
53-
54-
import { AuthenticatedTemplate, UnauthenticatedTemplate, useMsal } from '@azure/msal-react';
55-
56-
import './App.css';
57-
58-
import Button from 'react-bootstrap/Button';
47+
import React, { useState } from 'react';
48+
49+
import { PageLayout } from './components/PageLayout';
50+
import { loginRequest } from './authConfig';
51+
import { callMsGraph } from './graph';
52+
import { ProfileData } from './components/ProfileData';
53+
54+
import { AuthenticatedTemplate, UnauthenticatedTemplate, useMsal } from '@azure/msal-react';
55+
56+
import './App.css';
57+
58+
import Button from 'react-bootstrap/Button';
5959
```
6060

6161
### Adding the `ProfileContent` function
6262

63-
The `ProfileContent` function is used to render the user's profile information. In the *App.jsx* file, add the following code below your imports:
63+
The `ProfileContent` function is used to render the user's profile information after the user has signed in. This function will be called when the user selects the **Request Profile Information** button.
6464

65-
```javascript
66-
65+
1. In the *App.jsx* file, add the following code below your imports:
66+
67+
```JavaScript
6768
/**
6869
* Renders information about the signed-in user or a button to retrieve data about the user
6970
*/
7071
const ProfileContent = () => {
7172
const { instance, accounts } = useMsal();
7273
const [graphData, setGraphData] = useState(null);
73-
74+
7475
function RequestProfileData() {
7576
// Silently acquires an access token which is then attached to a request for MS Graph data
7677
instance
@@ -82,7 +83,7 @@ The `ProfileContent` function is used to render the user's profile information.
8283
callMsGraph(response.accessToken).then((response) => setGraphData(response));
8384
});
8485
}
85-
86+
8687
return (
8788
<>
8889
<h5 className="card-title">Welcome {accounts[0].name}</h5>
@@ -101,9 +102,11 @@ The `ProfileContent` function is used to render the user's profile information.
101102

102103
### Replacing the default function to render authenticated information
103104

104-
The following code will render based on whether the user is authenticated or not. Replace the default function `App()` to render authenticated information with the following code:
105+
The `MainContent` function is used to render the user's profile information after the user has signed in. This function will be called when the user selects the **Request Profile Information** button.
106+
107+
1. In the *App.jsx* file, replace the `App()` function with the following code:
105108

106-
```javascript
109+
```JavaScript
107110
/**
108111
* If a user is authenticated the ProfileContent component above is rendered. Otherwise a message indicating a user is not authenticated is rendered.
109112
*/
@@ -113,7 +116,7 @@ The following code will render based on whether the user is authenticated or not
113116
<AuthenticatedTemplate>
114117
<ProfileContent />
115118
</AuthenticatedTemplate>
116-
119+
117120
<UnauthenticatedTemplate>
118121
<h5>
119122
<center>
@@ -124,7 +127,7 @@ The following code will render based on whether the user is authenticated or not
124127
</div>
125128
);
126129
};
127-
130+
128131
export default function App() {
129132
return (
130133
<PageLayout>
@@ -134,7 +137,7 @@ The following code will render based on whether the user is authenticated or not
134137
</PageLayout>
135138
);
136139
}
137-
```
140+
```
138141

139142
## Calling the API from the application
140143

articles/active-directory/develop/tutorial-single-page-app-react-prepare-spa.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ To learn more about these packages refer to the documentation in [msal-browser](
116116
- The *Tenant ID* is the identifier of the tenant where the application is registered. Replace the `_Enter_the_Tenant_Info_Here` with the **Directory (tenant) ID** value that was recorded earlier from the overview page of the registered application.
117117
118118
1. Save the file.
119-
---
120119
121120
## Modify *index.js* to include the authentication provider
122121

0 commit comments

Comments
 (0)