Skip to content

Commit 4620f60

Browse files
committed
..
1 parent 2d1e257 commit 4620f60

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

website/docs/build-apps/how-to-guides/refresh-access-token.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
3-
## Refresh access token
2+
# Refresh access token
43

54
To keep your access uninterrupted and secure across all apps, follow these steps to refresh OAuth tokens and extend your authentication:
65

website/docs/packages/how-to-guides/use-query-inside-js-module.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ This page shows you how to create a reusable custom authentication module using
2323

2424
## Prerequisites
2525

26-
- A UI Package that has already been created. For more information, see [UI Modules tutorials](//packages/tutorial/ui-module).
26+
- A UI Package that has already been created. For more information, see [UI Modules tutorials](/packages/tutorial/ui-module).
2727
- An authenticated datasource with user sign-in endpoints.
2828

2929

3030

3131
## Configure package
3232

33-
To create a reusable and secure sign-in flow, you’ll configure a Login UI Module that handles user authentication, supports dynamic branding, and exposes login state back to the parent app. Follow these steps to build the login flow inside the package:
33+
Follow these steps to create a reusable and secure sign-in flow by configuring a Login UI Module. This module handles user authentication, supports dynamic branding, and exposes login state back to the parent app:
3434

3535

3636
1. In the **UI Module**, create the login interface using the following widgets:
@@ -78,7 +78,7 @@ The values for email and password are dynamically taken from the input widgets (
7878

7979
</dd>
8080

81-
3. Create a new JS Object inside the UI Module to manage the login logic. This function will call the `login` API query with the provided `email` and `password`, store the authentication token in local storage using `storeValue`, and navigate to the Home page upon successful authentication.
81+
3. Create a new JSObject inside the UI Module to manage the login logic. This function will call the `login` API query with the provided `email` and `password`, store the authentication token in local storage using `storeValue`, and navigate to the Home page upon successful authentication.
8282

8383
<dd>
8484

@@ -87,26 +87,30 @@ The values for email and password are dynamically taken from the input widgets (
8787
```js
8888
export default {
8989
async loginUser() {
90+
// Validate that both email and password fields are filled
9091
if (!emailInput.text || !passwordInput.text) {
9192
showAlert("Enter both email and password", "error");
9293
return { token: "", isLoggedIn: false };
9394
}
9495

9596
try {
97+
// Call the login API query with the user-provided credentials
9698
const response = await login.run({
9799
email: emailInput.text,
98100
password: passwordInput.text
99101
});
100102

103+
// If the API returns a token, store it and navigate to the Home page
101104
if (response.token) {
102-
await storeValue("access_token", response.token);
103-
navigateTo("Home");
104-
return { token: response.token, isLoggedIn: true };
105+
await storeValue("access_token", response.token); // Store token for app-wide access
106+
navigateTo("Home"); // Redirect user after successful login
107+
return { token: response.token, isLoggedIn: true }; // Return token and status to be used as module outputs
105108
} else {
106109
showAlert("Login failed", "error");
107110
return { token: "", isLoggedIn: false };
108111
}
109112
} catch (e) {
113+
// Handle any API or network errors
110114
showAlert("Invalid credentials", "error");
111115
return { token: "", isLoggedIn: false };
112116
}
@@ -119,7 +123,9 @@ For any future user actions, use the stored access token to access the relevant
119123

120124
</dd>
121125

122-
4. On the **UI** tab, set the **onClick** event of the Login button to run the `loginUser` function defined in the JSObject.
126+
4. In the **UI** tab, set the **onClick** event of the Login button to run the `loginUser` function defined in the JSObject.
127+
128+
123129

124130

125131
5. To customize the login UI based on the app using the module, use [Inputs](/packages/reference/ui-module#inputs) to pass values such as the application name and logo URL from the parent app. This allows each application to display its own branding, such as “HR Portal” or “CRM Dashboard”, without modifying the module.

0 commit comments

Comments
 (0)