Skip to content

Instantly share code, notes, and snippets.

@rajdesigner
rajdesigner / forgot_password.js
Created July 20, 2020 15:03
Recover Password in Cognito
/**
Recover Password in AWS cognito is a 2 step process through email. In first step AWS sends a verification code
this verification has to be passed to step 2 with new password
*/
recoverPasswordStep1(email) {
if (email.valid) {
const userData = {
Username: this.forgotparams.email,
Pool: userPool
@rajdesigner
rajdesigner / login.js
Created July 20, 2020 14:54
Login Using Cognito
/**
* This function will call the signIn() function from congnito AWS SDK.
* in login api.
*/
signinUser() {
this.loading = true;
this.loginparams.username = this.loginparams.username.trim();
this.loginparams.password = this.loginparams.password.trim()
try {
/** Create auth data */
/**
This function is used to add other attributes in user's cognito database
*/
createRegistrationDataAttr(name, email, mobile) {
var attributeList = [];
var dataEmail = {
Name: 'email',
Value: email // your email here
};
var dataPhoneNumber = {
@rajdesigner
rajdesigner / userpool_cognito.js
Created July 20, 2020 14:43
User Pool in Cognito
/**
*Pooldata const contain pooldata with user pool Id and client Id*
*/
const PoolData = {
UserPoolId: Constants.USER_POOL.POOL_ID,
ClientId: Constants.USER_POOL.CLIENT_ID
};
const userPool = new CognitoUserPool(PoolData);
@rajdesigner
rajdesigner / cognito_sign_up.js
Created July 20, 2020 14:40
It's consist a function of signup through cognito
signup() {
this.loading = true;
/* User attributes consists of other attributes you need to store in cognito */
let userAttributes = this.createRegistrationDataAttr(this.signinparams.name, this.signinparams.email, this.signinparams.contact_num);
try {
/* Sign up function */
userPool.signUp(this.signinparams.email, this.signinparams.password, userAttributes, null, ((err, result) => {
if (err) {
this.loading = false;