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

The Key to Unlocking Mobile App Monetization Strategies
The Key to Unlocking Mobile App Monetization Strategies
Discover how to unlock the full revenue potential of your mobile app with proven monetization strategies including advertising, in-app purchases, and subscriptions.
Key Considerations When Choosing an AI App Creator
Key Considerations When Choosing an AI App Creator
When choosing an AI app creator, it's essential to consider factors like integration capabilities, ease of use, and scalability. This article guides you through the key considerations to make an informed choice.
Tips for Effective Push Notifications in PWAs
Tips for Effective Push Notifications in PWAs
Discover the art of crafting effective push notifications for Progressive Web Apps (PWAs) that boost user engagement and ensure your messages stand out in a crowded digital space.
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