Enable Custom User Validation

Code Your Custom Authentication Logic

Now, we will code our custom logic that needs to be employed when an end user tries to register to your application.

The functions directory, BirthdayGreetings/functions/basic_function/ contains:

You will be adding code in the index.js file.

The function contains the following functionalities:

  • The end-user’s details will be provided as a JSON input to the Custom User Validation function.
  • The function is coded to implement a custom logic based upon which the end-user will either be authenticated or denied.
Note: For the purpose of this tutorial, we have coded an example logic for the Custom User Validation function where if the user's email provider is anyone other than Zylker Technology (@zylker.com) the end user will not be able to sign up to the application. You can either use the same or code a logic of your preference.

Copy the code given below and paste it in the index.js file in the BirthdayGreetings/functions/basic_function directory of your project, and save the file.

You can use any IDE of your choice to work with the application’s files.

Note: Please go through the code in this section to make sure you fully understand it.
    
index.js
copy
const catalyst = require('zcatalyst-sdk-node') module.exports = (context, basicIO) => { const catalystApp = catalyst.initialize(context) const requestDetails = catalystApp.userManagement().getSignupValidationRequest(basicIO) if (requestDetails) { if (requestDetails.user_details.email_id.includes('@zylker.com')) { basicIO.write(JSON.stringify({ status: 'success', user_details: { first_name: requestDetails.user_details.first_name, last_name: requestDetails.user_details.last_name, email_id: requestDetails.user_details.email_id, role_identifier: 'App User', org_id: '' } })) } else { // The user has failed authentication basicIO.write(JSON.stringify({ status: 'failure' })) } } context.close() }
View more
Notes:
  • Ensure that you change the domain name in line 6 with one that matches your requirement.

  • You can also use this SDK to code your own custom logic instead of the one implemented above.

Deploy the Function and Configure Custom User Validation

To apply this custom logic, we need to deploy this function to the console to ensure that it is available to enable the Custom User Validation option present in the console.

To deploy the function, execute the following CLI command to deploy the function component alone to the console.

copy
$
catalyst deploy --only functions
Info: You can also alternatively choose to deploy just the Custom User Validation function using the following command:

catalyst deploy –only functions:function_name

catalyst_tutorials_jobscheduling_deploy_only_func

Function endpoints will be created for all of the functions. This will allow you to access the functions directly.

The functions will be deployed to the console. They can be accessed in the console using the Functions component in the Serverless section of the console.

catalyst_tutorials_jobscheduling_serverless_func_view
Note: While we have deployed all of the functions of the project to the console, we will be redeploying them once again after we code the Advanced I/O and Job functions.

Now, go to the Authentication component present in the Cloud Scale section of the console and implement the following steps:

  1. Navigate to the Whitelisting section in the Authentication component, and click the Custom User Validation toggle.

    catalyst_tutorials_jobscheduling_authentication_csu_start
  2. Select the Basic I/O function from the drop-down in the pop-up.

    catalyst_tutorials_jobscheduling_authentication_csu_func_sel
  3. Click Configure.

    catalyst_tutorials_jobscheduling_authentication_csu_cmpltd

The Custom User Validation function has been enabled for the project, and the end-users signing up for your application will now be additionally authenticated using this function.

Note: You can find out about all of the features present in the Whitelisting section form in this help document.

Last Updated 2025-04-01 11:10:20 +0530 +0530