Grow with AppMaster Grow with AppMaster.
Become our partner arrow ico

How to Identify the Current User in AppMaster

How to Identify the Current User in AppMaster

When your application is running, you often need to know who is running certain processes. This is necessary in order to correctly distribute data and grant or restrict access to different resources. This feature is used in almost every application.

How to identify the current user in AppMaster

On the backend side

There is an Auth: Get Current User block in AppMaster to detect the current user. It is provided by the Auth module. You can find it in the business-processes editor in the backend tab on the left.

Get Current User block in AppMaster

This block returns a record from the User database that belongs to the user who ran the block.

Important

The Auth: Get Current User block works only for authorized users. In all other cases, the result of this block will be undefined.

With this simple method, we can get the current user of our application. However, this block only exists in the backend, but in most cases, it is required to identify the user in the application’s frontend.

On the frontend side

To run processes in the backend from the frontend the endpoints are used. You can find more information about them in this article.

For the Auth: Get Current User block, you need to create a new endpoint, as it is done on the screenshot below:

Get Current User block

To invoke the endpoint from the frontend, the Server Request GET /user/get-current block has to be used (in this current case). The endpoints usage flow of the endpoint is the same for web and mobile applications.

Server Request GET

Working with the current user

Let's see some examples of the Auth: Get Current User block usage. The block itself returns a record from the User table. In order to get specific data from the record, you need to expand this record with the Expand User block:

Get Current User

All the fields from the output can be used in a specific way. For example to check if the user account is confirmed the Confirmed field of a boolean type can be used as in the image below.

AppMaster

Parameter With

With parameter in the output specifies if the request has to be performed with the use of related tables. So, for example, to get data from the User Sessions table for the current User object (that is a list of current user sessions), you need to specify the value for with field to search for the associated table (User Sessions in this case).

Parameter With

Important!

The With parameter complicates the query and therefore increases its processing time. It is not used by default and is used only if necessary.

Conclusion

In this article, we learned how to determine the current user of the application on the backend side and on the frontend side. This function is one of the most frequently used in application development. With AppMaster, you can perform these requests easily with a few combinations of business process blocks.

Related Posts

What Are Electronic Health Records (EHR) and Why Are They Essential in Modern Healthcare?
What Are Electronic Health Records (EHR) and Why Are They Essential in Modern Healthcare?
Explore the benefits of Electronic Health Records (EHR) in enhancing healthcare delivery, improving patient outcomes, and transforming medical practice efficiency.
Visual Programming Language vs Traditional Coding: Which Is More Efficient?
Visual Programming Language vs Traditional Coding: Which Is More Efficient?
Exploring the efficiency of visual programming languages versus traditional coding, highlighting advantages and challenges for developers seeking innovative solutions.
How a No Code AI App Builder Helps You Create Custom Business Software
How a No Code AI App Builder Helps You Create Custom Business Software
Discover the power of no-code AI app builders in creating custom business software. Explore how these tools enable efficient development and democratize software creation.
GET STARTED FREE
Inspired to try this yourself?

The best way to understand the power of AppMaster is to see it for yourself. Make your own application in minutes with free subscription

Bring Your Ideas to Life