Skip to content

Commit 76f0b9b

Browse files
Apply suggestions from code review
Co-Authored-By: John Papa <[email protected]>
1 parent 64a71ba commit 76f0b9b

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

articles/static-apps/user-information.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ User information is available in the app via the `x-ms-client-principal` request
2020
| Property | Description |
2121
|-----------|---------|
2222
| `identityProvider` | The name of the [identity provider](authentication-authorization.md). |
23-
| `userId` | An Azure Static Web Apps-specific unique identifier for the user. <ul><li>The value is unique on a per-app basis. For instance, the same user returns a different `userId` value on a different Static App.<li>The value persists for the lifetime of a user. If you delete and then add the same user back to the app, then the `userId` is a different value.</ul>|
23+
| `userId` | An Azure Static Web Apps-specific unique identifier for the user. <ul><li>The value is unique on a per-app basis. For instance, the same user returns a different `userId` value on a different Static Web App.<li>The value persists for the lifetime of a user. If you delete and then add the same user back to the app, then the `userId` is a different value.</ul>|
2424
| `userDetails` | Username or email address of the user. Some providers return the [user's email address](authentication-authorization.md), while others send the [user handle](authentication-authorization.md). |
2525
| `userRoles` | An array of the [user's assigned roles](authentication-authorization.md). |
2626

@@ -37,7 +37,7 @@ The following example is a sample decoded `x-ms-client-principal` payload:
3737

3838
## Direct access
3939

40-
To get direct access to the client principal data, you can send a `GET` request to the `/.auth/me` route. When the state of your view is driven by authorization, use this approach for the best performance.
40+
You can send a `GET` request to the `/.auth/me` route and receive direct access to the client principal data. When the state of your view is driven by authorization, use this approach for the best performance.
4141

4242
When users are logged-in, the payload from this request is a client principal JSON object. Requests from unauthenticated users returns `null`.
4343

@@ -65,7 +65,7 @@ axios.get("/.auth/me").then(response => {
6565

6666
Client principal data is passed to API functions in the request header. To make this information accessible to the browser, you can return user data from a function.
6767

68-
### In the function
68+
### API access in the function
6969

7070
The following example function, named `user`, shows how to return user information to the client.
7171

@@ -88,22 +88,10 @@ module.exports = async function (context, req) {
8888
Using the [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch) API, you can access the API's response using the following syntax.
8989

9090
```javascript
91-
fetch("/api/user/")
92-
.then(response => response.json())
93-
.then(payload => {
94-
const { clientPrincipal } = payload;
95-
console.log(clientPrincipal);
96-
});
97-
```
98-
99-
Libraries like [axios](https://github.com/axios/axios) make accessing the response even easier.
100-
101-
```javascript
102-
axios.get(`/api/user`).then(response => {
103-
const { clientPrincipal } = response.data;
104-
console.log(clientPrincipal);
105-
});
106-
```
91+
const response = await fetch("/api/user/");
92+
const payload = await response.json();
93+
const { clientPrincipal } = payload;
94+
console.log(clientPrincipal);
10795

10896
## Next steps
10997

0 commit comments

Comments
 (0)