@gravitywelluk/aws
Version:
Library of commonly used AWS wrapper functions to communicate with the AWS SDK
57 lines (56 loc) • 2.35 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyBasicUserAccount = void 0;
const Joi = __importStar(require("joi"));
const validation_utils_1 = require("@gravitywelluk/validation-utils");
const _1 = require(".");
const utils_1 = require("../utils");
/**
* Verify a user's account by entering the confirmation code sent to them via text or email
* This code is checked and if it matches then the user's account is enabled and they can log in with the details they originally provided
*
* @param verifyBasicUserParams The parameters required to verify a user's account
*/
const verifyBasicUserAccount = async (verifyBasicUserParams) => {
const cognito = (0, _1.cognitoConfigure)();
const { error } = Joi.object({
clientId: Joi.string().required(),
confirmationCode: Joi.string().required(),
email: Joi.string().email().required()
}).validate(verifyBasicUserParams);
// Error if there any Joi validation errors
if (error) {
throw new validation_utils_1.JoiError(error);
}
try {
const response = await cognito.confirmSignUp({
ClientId: verifyBasicUserParams.clientId,
ConfirmationCode: verifyBasicUserParams.confirmationCode,
Username: verifyBasicUserParams.email
}).promise();
return response;
}
catch (error) {
throw new utils_1.AwsError(error);
}
};
exports.verifyBasicUserAccount = verifyBasicUserAccount;