We have covered step by step guide on implementation of magic link login on nocode backend
Magic link is a passwordless login mechanism that uses a valid user email address to authenticate and log users into an application. It works by sending a unique link to the user's email. The user clicks the link, which verifies the token embedded in it, and completes the authentication process, provided the link originates from a trusted site.
user
table in database to verify the existence of the email.We will login into Fireapis and create a user
table with email
as one of the fields to process(storing & validating) user authentication.
Next, I will go to Logics tab, and create a logic as Magic link logic.
Next, Configuring input payload for the logic This payload will be used when integrating the logic with the frontend.
Below is an example payload configuration:
{ "email": "[email protected]" }
We will add five actions to build magic link logic. These actions will validate and send a email with login link to the provided email
The first action will be Database Query
Action (add this by clicking the Add Action button and selecting Database Query
as the action type).
I am going to get the user details with this email id, in order to check whether this user is a valid user or not.
This action retrieves user details based on the provided email address to check if the user exists. Configure it as follows:
user
id, name, email, created_at
SELECT
Add a condition in the Condition Builder:
AND
email
=
payload.email
(use the Dynamic Data Source Selector interface).
I have configured the database query to get the user detail and next would be testing logics till our first action to get expected results.
Test the logic up to this action using the Test tab in the Logics configuration.
Expected Results
{
"data": {
"action_1_result": [
{
"email": "[email protected]",
"first_name": "vasanth",
"id": 1,
"last_name": "fireapis",
"created_at": "2024-09-08T13:43:03.000Z"
}
]
}
}
Next would be adding a Build Condition action to check if the user is there or not, if not will create new user into user
table (with consideration other details of user will be updated in other page in FE after login).
The next step is to add a Build condition action
if condition.
For this case, add a Data Transformation Action to return the user object retrieved from the database (We have attached screenshots on the configuration that's done which will return the user object from previous action, i.e: from DB).
Next, add an otherwise if condition
Configure it as follows:
user
INSERT
email
- value wll be taken from input payload(can be done using Dynamic Data Source Selector).
This above action will check if user is null, then create the user
Now, I will test our logics up to the second action. For this, I will follow the same procedure as described in testing above action.
Test Case -1
If user not exists in database then create user.
Results
{
"data": {
"action_1_result": [],
"action_2_result": [
{
"id": 4,
"email": "[[email protected]](mailto:[email protected])",
"first_name": null,
"last_name": null,
"created_at": "2024-12-31T10:08:00.573Z",
"updated_at": "2024-12-31T10:08:00.573Z"
}
]
}
}
Test Case - 2
If user exists in database, then no duplicate user should be created.
Results
{
"data": {
"action_1_result": [
{
"email": "[email protected]",
"first_name": "vasanth",
"id": 1,
"last_name": "fireapis",
"created_at": "2024-09-08T13:43:03.000Z"
}
],
"action_2_result": {
"email": "[email protected]",
"first_name": "vasanth",
"id": 1,
"last_name": "fireapis",
"created_at": "2024-09-08T13:43:03.000Z"
}
}
}
In this first part of the blog, we covered the basics of building magic link logic by setting up the database query and conditional actions. We’ve demonstrated how to verify user existence and handle scenarios for creating new users seamlessly. This helps to build the Nocode development for handling user authentication.
In Part-2, we’ll complete the logic by adding the steps for sending the email, generating tokens, and validating the magic link. Stay tuned for the next part!