You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Update imports to use components in the application
41
41
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.
43
43
44
44
1. In the *src* folder, open *App.jsx* and replace the contents of the file with the following code snippet to request access.
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.
64
64
65
-
```javascript
66
-
65
+
1. In the *App.jsx* file, add the following code below your imports:
66
+
67
+
```JavaScript
67
68
/**
68
69
* Renders information about the signed-in user or a button to retrieve data about the user
69
70
*/
70
71
constProfileContent= () => {
71
72
const { instance, accounts } =useMsal();
72
73
const [graphData, setGraphData] =useState(null);
73
-
74
+
74
75
functionRequestProfileData() {
75
76
// Silently acquires an access token which is then attached to a request for MS Graph data
76
77
instance
@@ -82,7 +83,7 @@ The `ProfileContent` function is used to render the user's profile information.
@@ -101,9 +102,11 @@ The `ProfileContent` function is used to render the user's profile information.
101
102
102
103
### Replacing the default function to render authenticated information
103
104
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:
105
108
106
-
```javascript
109
+
```JavaScript
107
110
/**
108
111
* If a user is authenticated the ProfileContent component above is rendered. Otherwise a message indicating a user is not authenticated is rendered.
109
112
*/
@@ -113,7 +116,7 @@ The following code will render based on whether the user is authenticated or not
113
116
<AuthenticatedTemplate>
114
117
<ProfileContent />
115
118
</AuthenticatedTemplate>
116
-
119
+
117
120
<UnauthenticatedTemplate>
118
121
<h5>
119
122
<center>
@@ -124,7 +127,7 @@ The following code will render based on whether the user is authenticated or not
124
127
</div>
125
128
);
126
129
};
127
-
130
+
128
131
exportdefaultfunctionApp() {
129
132
return (
130
133
<PageLayout>
@@ -134,7 +137,7 @@ The following code will render based on whether the user is authenticated or not
Copy file name to clipboardExpand all lines: articles/active-directory/develop/tutorial-single-page-app-react-prepare-spa.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,7 +116,6 @@ To learn more about these packages refer to the documentation in [msal-browser](
116
116
- 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.
117
117
118
118
1. Save the file.
119
-
---
120
119
121
120
## Modify *index.js* to include the authentication provider
0 commit comments