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
Copy file name to clipboardExpand all lines: website/docs/packages/how-to-guides/use-query-inside-js-module.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,14 +23,14 @@ This page shows you how to create a reusable custom authentication module using
23
23
24
24
## Prerequisites
25
25
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).
27
27
- An authenticated datasource with user sign-in endpoints.
28
28
29
29
30
30
31
31
## Configure package
32
32
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:
34
34
35
35
36
36
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 (
78
78
79
79
</dd>
80
80
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.
82
82
83
83
<dd>
84
84
@@ -87,26 +87,30 @@ The values for email and password are dynamically taken from the input widgets (
87
87
```js
88
88
exportdefault {
89
89
asyncloginUser() {
90
+
// Validate that both email and password fields are filled
90
91
if (!emailInput.text||!passwordInput.text) {
91
92
showAlert("Enter both email and password", "error");
92
93
return { token:"", isLoggedIn:false };
93
94
}
94
95
95
96
try {
97
+
// Call the login API query with the user-provided credentials
96
98
constresponse=awaitlogin.run({
97
99
email:emailInput.text,
98
100
password:passwordInput.text
99
101
});
100
102
103
+
// If the API returns a token, store it and navigate to the Home page
101
104
if (response.token) {
102
-
awaitstoreValue("access_token", response.token);
103
-
navigateTo("Home");
104
-
return { token:response.token, isLoggedIn:true };
105
+
awaitstoreValue("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
105
108
} else {
106
109
showAlert("Login failed", "error");
107
110
return { token:"", isLoggedIn:false };
108
111
}
109
112
} catch (e) {
113
+
// Handle any API or network errors
110
114
showAlert("Invalid credentials", "error");
111
115
return { token:"", isLoggedIn:false };
112
116
}
@@ -119,7 +123,9 @@ For any future user actions, use the stored access token to access the relevant
119
123
120
124
</dd>
121
125
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
+
123
129
124
130
125
131
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