Skip to content

Commit f906c45

Browse files
committed
Replace userContext with User
1 parent cbce7fd commit f906c45

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

settings/authentication-personalization/authentication-setup/jwt.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you don’t have a dashboard, or if you want to keep your dashboard and docs
1818
<Step title="Create a login flow">
1919
Create a login flow that does the following:
2020
- Authenticate the user
21-
- Create a JWT containing the authenticated user's info in the [UserInfo](../sending-data) format
21+
- Create a JWT containing the authenticated user's info in the [User](../sending-data) format
2222
- Sign the JWT with the secret key, using the EdDSA algorithm
2323
- Create a redirect URL back to the `/login/jwt-callback` path of your docs, including the JWT as the hash
2424
</Step>
@@ -54,7 +54,7 @@ const TWO_WEEKS_IN_MS = 1000 * 60 * 60 * 24 * 7 * 2;
5454
const signingKey = await jose.importPKCS8(process.env.MINTLIFY_PRIVATE_KEY, 'EdDSA');
5555

5656
export async function handleRequest(req: Request, res: Response) {
57-
const userInfo = {
57+
const user = {
5858
expiresAt: Math.floor((Date.now() + TWO_WEEKS_IN_MS) / 1000), // 2 week session expiration
5959
groups: res.locals.user.groups,
6060
content: {
@@ -63,7 +63,7 @@ export async function handleRequest(req: Request, res: Response) {
6363
},
6464
};
6565

66-
const jwt = await new jose.SignJWT(userInfo)
66+
const jwt = await new jose.SignJWT(user)
6767
.setProtectedHeader({ alg: 'EdDSA' })
6868
.setExpirationTime('10 s') // 10 second JWT expiration
6969
.sign(signingKey);

settings/authentication-personalization/authentication-setup/oauth.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If you have an existing OAuth server, you can integrate with Mintlify for a seam
2626
</Step>
2727
<Step title="Create your Info API (Optional)">
2828
If you want to take advantage of authentication's customization features, you'll need to create an endpoint to retrieve info about your users.
29-
Create an API endpoint that can be accessed with an OAuth access token, and responds with a JSON payload following the [UserInfo](../sending-data) format.
29+
Create an API endpoint that can be accessed with an OAuth access token, and responds with a JSON payload following the [User](../sending-data) format.
3030

3131
Return to your [Mintlify authentication settings](https://dashboard.mintlify.com/products/authentication) and add the Info API URL
3232
to your OAuth configuration.

settings/authentication-personalization/personalization-setup/jwt.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you don’t have a dashboard, or if you want to keep your dashboard and docs
1919
<Step title="Create a login flow">
2020
Create a login flow that does the following:
2121
- Authenticate the user
22-
- Create a JWT containing the authenticated user's info in the [UserInfo](../sending-data) format
22+
- Create a JWT containing the authenticated user's info in the [User](../sending-data) format
2323
- Sign the JWT with the secret key, using the EdDSA algorithm
2424
- Create a redirect URL back to your docs, including the JWT as the hash
2525
</Step>
@@ -54,7 +54,7 @@ const TWO_WEEKS_IN_MS = 1000 * 60 * 60 * 24 * 7 * 2;
5454
const signingKey = await jose.importPKCS8(process.env.MINTLIFY_PRIVATE_KEY, 'EdDSA');
5555

5656
export async function handleRequest(req: Request, res: Response) {
57-
const userInfo = {
57+
const user = {
5858
expiresAt: Math.floor((Date.now() + TWO_WEEKS_IN_MS) / 1000),
5959
groups: res.locals.user.groups,
6060
content: {
@@ -63,7 +63,7 @@ export async function handleRequest(req: Request, res: Response) {
6363
},
6464
};
6565

66-
const jwt = await new jose.SignJWT(userInfo)
66+
const jwt = await new jose.SignJWT(user)
6767
.setProtectedHeader({ alg: 'EdDSA' })
6868
.setExpirationTime('10 s')
6969
.sign(signingKey);

settings/authentication-personalization/personalization-setup/oauth.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If you have an existing OAuth server that supports the PKCE flow, you can integr
1313

1414
<Steps>
1515
<Step title="Create your Info API">
16-
Create an API endpoint that can be accessed with an OAuth access token, and responds with a JSON payload following the [UserInfo](../sending-data) format. Take note of the scope or scopes required to access this endpoint.
16+
Create an API endpoint that can be accessed with an OAuth access token, and responds with a JSON payload following the [User](../sending-data) format. Take note of the scope or scopes required to access this endpoint.
1717
</Step>
1818
<Step title="Configure your Personalization settings">
1919
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/products/authentication), select the OAuth option, and fill out the required fields:

settings/authentication-personalization/personalization-setup/shared-session.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This method utilizes the session authentication info already stored in your user
1313

1414
<Steps>
1515
<Step title="Create your Info API">
16-
Create an API endpoint that uses session authentication to identify users, and responds with a JSON payload following the [UserInfo](../sending-data) format.
16+
Create an API endpoint that uses session authentication to identify users, and responds with a JSON payload following the [User](../sending-data) format.
1717

1818
If the API domain does not *exactly match* the docs domain:
1919
- Add the docs domain to your API's `Access-Control-Allow-Origin` header (must not be `*`)

settings/authentication-personalization/personalization.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,36 @@ three major features of Personalization:
2121

2222
### Customizing MDX Content
2323

24-
When writing content, you can use the `userContext` variable to access the information you have sent to your docs. Here's a simple example:
24+
When writing content, you can use the `user` variable to access the information you have sent to your docs. Here's a simple example:
2525

26-
Hello, {userContext.name ?? 'reader'}!
26+
Hello, {user.name ?? 'reader'}!
2727

2828
```jsx
29-
Hello, {userContext.name ?? 'reader'}!
29+
Hello, {user.name ?? 'reader'}!
3030
```
3131
3232
This feature becomes even more powerful when paired with custom data about the user. Here's a real world example that allows us to give specific instructions on how to access the Personalization feature based on the customer's existing plan:
3333
3434
Personalization is an enterprise feature. {
35-
userContext.org === undefined
35+
user.org === undefined
3636
? <>To access this feature, first create an account at the <a href="https://dashboard.mintlify.com/login">Mintlify dashboard</a>.</>
37-
: userContext.org.plan !== 'enterprise'
38-
? <>You are currently on the ${userContext.org.plan ?? 'free'} plan. To speak to our team about upgrading, <a href="mailto:[email protected]">contact our sales team</a>.</>
37+
: user.org.plan !== 'enterprise'
38+
? <>You are currently on the ${user.org.plan ?? 'free'} plan. To speak to our team about upgrading, <a href="mailto:[email protected]">contact our sales team</a>.</>
3939
: <>To request this feature for your enterprise org, <a href="mailto:[email protected]">contact our team</a>.</>
4040
}
4141
4242
```jsx
4343
Personalization is an enterprise feature. {
44-
userContext.org === undefined
44+
user.org === undefined
4545
? <>To access this feature, first create an account at the <a href="https://dashboard.mintlify.com/login">Mintlify dashboard</a>.</>
46-
: userContext.org.plan !== 'enterprise'
47-
? <>You are currently on the ${userContext.org.plan ?? 'free'} plan. To speak to our team about upgrading, <a href="mailto:[email protected]">contact our sales team</a>.</>
46+
: user.org.plan !== 'enterprise'
47+
? <>You are currently on the ${user.org.plan ?? 'free'} plan. To speak to our team about upgrading, <a href="mailto:[email protected]">contact our sales team</a>.</>
4848
: <>To request this feature for your enterprise org, <a href="mailto:[email protected]">contact our team</a>.</>
4949
}
5050
```
5151
5252
<Note>
53-
The information in `userContext` is only available after a user has logged in. For logged out users, the value of `userContext` will be `{}`. To prevent the page from crashing for logged-out users, always use optional chaining on your `userContext` fields, e.g. `{userContext.org?.plan}`
53+
The information in `user` is only available after a user has logged in. For logged out users, the value of `user` will be `{}`. To prevent the page from crashing for logged-out users, always use optional chaining on your `user` fields, e.g. `{user.org?.plan}`
5454
</Note>
5555
5656
### Prefilling API Keys
@@ -71,9 +71,9 @@ groups: ['admin']
7171
---
7272
```
7373
74-
Here's a table that displays whether a page is shown for different combinations of `groups` in UserInfo and page metadata:
74+
Here's a table that displays whether a page is shown for different combinations of `groups` in User and page metadata:
7575
76-
| | `groups` not in UserInfo | `groups: []` in UserInfo | `groups: ['admin']` in UserInfo |
76+
| | `groups` not in User | `groups: []` in User | `groups: ['admin']` in User |
7777
| :------------------------------ | :----------------------: | :----------------------: | :-----------------------------: |
7878
| `groups` not in metadata | ✅ | ✅ | ✅ |
7979
| `groups: []` in metadata | ❌ | ❌ | ❌ |

settings/authentication-personalization/sending-data.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: 'The shape of user data you can use to personalize your docs'
66
Depending on your Handshake method, your API will respond with either a raw JSON object or a signed JWT. The shape of the data is the same for both:
77

88
```tsx
9-
type UserInfo = {
9+
type User = {
1010
expiresAt?: number;
1111
groups?: string[];
1212
content?: Record<string, any>;
@@ -36,7 +36,7 @@ type UserInfo = {
3636
path="content"
3737
type="object"
3838
>
39-
A bag of values that can be accessed from within MDX content using the `userContext` variable. For example, if you have supplied `{ firstName: 'Ronan' }` as your content field, you can use the following in your MDX: `Good morning, {userContext.firstName}!`
39+
A bag of values that can be accessed from within MDX content using the `user` variable. For example, if you have supplied `{ firstName: 'Ronan' }` as your content field, you can use the following in your MDX: `Good morning, {user.firstName}!`
4040
</ParamField>
4141
<ParamField
4242
path="apiPlaygroundInputs"

0 commit comments

Comments
 (0)