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
To keep your access uninterrupted and secure across all apps, follow these steps to refresh OAuth tokens and extend your authentication:
6
+
7
+
1. Create a query module to call the token refresh endpoint provided by your authentication service. For OAuth services, ensure that you add the refresh token in the request payload to receive a new access token.
8
+
9
+
<dd>
10
+
11
+
*Example:*
12
+
13
+
```api
14
+
https://api.example.io/api/user/token-auth/
15
+
```
16
+
17
+
</dd>
18
+
19
+
2. Create a new JS module to refresh the token:
20
+
21
+
<dd>
22
+
23
+
*Example:*
24
+
25
+
```jsx
26
+
exportdefault {
27
+
refreshAccessToken: () => {
28
+
// Retrieving the refresh token from the appsmith store
29
+
constrefreshToken=appsmith.store.refreshtoken;
30
+
31
+
// Checking if a refresh token exists
32
+
if (refreshToken) {
33
+
// Executing the refresh API with the retrieved refresh token
This page shows how to create a custom authentication module using packages, which allows you to reuse the same module across different applications to authenticate users efficiently.
22
-
21
+
This page shows you how to create a reusable custom authentication module using UI Packages. It guides you through building a secure login flow that can be shared across multiple applications, while allowing each app to customize its branding and behavior as needed.
23
22
24
23
25
24
## Prerequisites
@@ -31,38 +30,26 @@ This page shows how to create a custom authentication module using packages, whi
31
30
32
31
## Configure package
33
32
34
-
To secure your Appsmith application, you will need to set up a sign-in flow that requires users to authenticate before accessing the app. Follow these steps to create the sign-in flow:
35
-
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:
1. In the UI Module, create the login interface using the following widgets:
36
+
1. In the **UI Module**, create the login interface using the following widgets:
53
37
54
38
<dd>
55
39
56
40
-**Input Widget** (`emailInput`) – Used to capture the user's email or username.
57
-
58
41
-**Input Widget** (`passwordInput`) – Used to capture the user's password. Set the input type to password to mask the input.
59
-
60
42
-**Button Widget** (`loginButton`) – Triggers the login process when clicked.
61
-
62
43
-**Text Widget** – Displays the application name.
63
-
64
44
-**Image Widget** – Displays the brand logo.
65
45
46
+
47
+
<ZoomImage
48
+
src="/img/login-module.png"
49
+
alt=""
50
+
caption=""
51
+
/>
52
+
66
53
</dd>
67
54
68
55
@@ -91,7 +78,7 @@ The values for email and password are dynamically taken from the input widgets (
91
78
92
79
</dd>
93
80
94
-
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 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.
95
82
96
83
<dd>
97
84
@@ -102,7 +89,7 @@ export default {
102
89
asyncloginUser() {
103
90
if (!emailInput.text||!passwordInput.text) {
104
91
showAlert("Enter both email and password", "error");
105
-
return;
92
+
return { token:"", isLoggedIn:false };
106
93
}
107
94
108
95
try {
@@ -113,13 +100,15 @@ export default {
113
100
114
101
if (response.token) {
115
102
awaitstoreValue("access_token", response.token);
116
-
// Navigate to the 'Home' page upon successful authentication
117
103
navigateTo("Home");
104
+
return { token:response.token, isLoggedIn:true };
118
105
} else {
119
106
showAlert("Login failed", "error");
107
+
return { token:"", isLoggedIn:false };
120
108
}
121
109
} catch (e) {
122
110
showAlert("Invalid credentials", "error");
111
+
return { token:"", isLoggedIn:false };
123
112
}
124
113
}
125
114
};
@@ -130,23 +119,24 @@ For any future user actions, use the stored access token to access the relevant
130
119
131
120
</dd>
132
121
133
-
4.Set the **onClick** event of the Login button to run the loginUser function defined in the JS Object.
122
+
4.On the **UI** tab, set the **onClick** event of the Login button to run the `loginUser` function defined in the JSObject.
134
123
135
-
5. To dynamically change the login UI based on the app using the module, use inputs to pass data from the parent application into the module. This allows each app to control elements like the displayed app name and logo without modifying the module itself.
124
+
125
+
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.
136
126
137
127
<dd>
138
128
139
129
*Example:* Create two inputs, `appName` and `logoUrl`, to reuse the same login module across different applications such as an HR portal or a CRM dashboard.
140
130
141
131
142
-
`appName`: Set the Text widget’s text property to: `{{ this.params.appName }}`
132
+
-`appName`: Set the Text widget’s text property to: `{{ inputs.appName }}`
133
+
-`logoUrl`: Set the Image widget’s source property to: `{{ inputs.logoUrl }}`
143
134
144
-
`logoUrl`: Set the Image widget’s source property to: `{{ this.params.logoUrl }}`
145
135
146
136
</dd>
147
137
148
138
149
-
6. To pass login state or token ID from the module back to the parent app, use outputs. This allows you to expose specific values such as authentication tokens or login status that the parent application can access and respond to.
139
+
6. To pass login state or token ID from the module back to the parent app, use [Outputs](/packages/reference/ui-module#outputs). This allows you to expose specific values such as authentication tokens or login status that the parent application can access and respond to.
150
140
151
141
<dd>
152
142
@@ -159,14 +149,13 @@ For any future user actions, use the stored access token to access the relevant
159
149
160
150
The token can then be accessed in the parent app using `LoginModule1.outputs.token`.
161
151
162
-
163
152
</dd>
164
153
165
154
166
-
7. Publish the package.
155
+
7.**Publish** the package.
167
156
168
157
169
-
8. To integrate custom authentication into your app, open the application and navigate to the UI tab. Drag the login module onto the desired page and configure the appName and logoUrl inputs.
158
+
8. To integrate custom authentication into your app, open the application and navigate to the **UI** tab. Drag the `login` module onto the desired page and configure the `appName` and `logoUrl` inputs.
170
159
171
160
<dd>
172
161
@@ -176,100 +165,14 @@ Based on your application’s requirements, you can use the token output to stor
176
165
</dd>
177
166
178
167
179
-
With this setup, the login module can now securely authenticate users, dynamically adapt to different applications, and expose login state back to the parent app. Once a user logs in successfully, they are automatically navigated to the home page or any other page you specify through input configuration.
180
-
181
-
182
-
If your application uses short-lived access tokens, consider implementing a refresh token strategy to maintain session continuity. For details on when and how to use refresh tokens, see the Refresh Token Handling Guide.
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
## Refresh access token
194
-
195
-
To keep your access uninterrupted and secure across all apps, follow these steps to refresh OAuth tokens and extend your authentication:
196
-
197
-
1. Create a query module to call the token refresh endpoint provided by your authentication service. For OAuth services, ensure that you add the refresh token in the request payload to receive a new access token.
198
-
199
-
<dd>
200
-
201
-
*Example:*
202
-
203
-
```api
204
-
https://api.example.io/api/user/token-auth/
205
-
```
206
-
207
-
</dd>
208
-
209
-
2. Create a new JS module to refresh the token:
210
-
211
-
<dd>
212
-
213
-
*Example:*
214
-
215
-
```jsx
216
-
exportdefault {
217
-
refreshAccessToken: () => {
218
-
// Retrieving the refresh token from the appsmith store
219
-
constrefreshToken=appsmith.store.refreshtoken;
220
-
221
-
// Checking if a refresh token exists
222
-
if (refreshToken) {
223
-
// Executing the refresh API with the retrieved refresh token
Now you can use the JS module within your app to fetch details using query or refresh tokens on page load, ensuring continuous authentication access.
268
-
269
168
169
+
### See also
270
170
171
+
-[Refresh access token](/docs/build-apps/how-to-guides/refresh-access-token.md) – Use this guide to implement a refresh token strategy and maintain session continuity for apps using short-lived access tokens. View guide
271
172
173
+
-[Module inputs](/packages/reference/ui-module#inputs) – Learn how to define and use inputs to customize module behavior such as dynamic app names, logos, or redirect paths. View reference
272
174
175
+
-[Module outputs](/packages/reference/ui-module#outputs) – Understand how to expose values like access tokens or login status from a module to the parent app. View reference
Copy file name to clipboardExpand all lines: website/docs/packages/overview.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,10 +52,10 @@ Inside a Code Package, you can create two types of modules—Query Modules and J
52
52
### UI Packages
53
53
54
54
55
-
UI Packages allow you to create and distribute reusable UI components across multiple applications in the same workspace.
55
+
UI Packages are reusable bundles that group user interface components and related logic, which can be shared across applications within the same workspace. Inside a UI Package, you can create one or more UI Modules.
56
56
57
+
A **UI Module** combines widgets, queries, JavaScript, inputs, and outputs into a self-contained, configurable component. This allows you to build dynamic, branded UI blocks—like login forms or dashboards—that can be reused and customized across different applications without duplicating logic.
57
58
58
-
***UI Modules:** Reusable widgets and UI components designed to enhance modularity and reusability in the user interface, streamlining the development and maintenance of consistent UI elements across multiple applications.
0 commit comments