PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 4, 2022

[FIXED] How to set sign up with email or phone-number option in AWS Cognito?

 September 04, 2022     amazon-cognito, amazon-web-services, authentication     No comments   

Issue

How to set sign up with email or phone-number option in AWS Cognito?

So I would like to have a simple sign-up. I want users to sign-up with username, email/phone-number, password and repeat password. How can I configure the ability to make it that either email or phone-number is required?


Solution

A way to require attributes conditionally is to have them as not required in the User Pool settings and define a Pre sign-up Lambda trigger function that will verify the presence of at least one of the fields at Sign up, and reject if none is provided (similar to this example):

exports.handler = (event, context, callback) => {
    // Impose a condition that the email or phone_number is provided.
    var userAttributes = event.request.userAttributes;
    if (!userAttributes.email && !userAttributes.phone_number) {
        var error = new Error("Cannot register users without email or phone number");
        // Return error to Amazon Cognito, fail sign up
        callback(error, event);
    }
    // Return to Amazon Cognito, proceed with sign up
    callback(null, event);
};


Answered By - ammendonca
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing