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

How to Develop a Scalable Hotel Booking System: A Complete Guide
How to Develop a Scalable Hotel Booking System: A Complete Guide
Learn how to develop a scalable hotel booking system, explore architecture design, key features, and modern tech choices to deliver seamless customer experiences.
Step-by-Step Guide to Developing an Investment Management Platform from Scratch
Step-by-Step Guide to Developing an Investment Management Platform from Scratch
Explore the structured path to creating a high-performance investment management platform, leveraging modern technologies and methodologies to enhance efficiency.
How to Choose the Right Health Monitoring Tools for Your Needs
How to Choose the Right Health Monitoring Tools for Your Needs
Discover how to select the right health monitoring tools tailored to your lifestyle and requirements. A comprehensive guide to making informed decisions.
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