johnoliver2342
03/30/2023, 5:14 AM[{ "email": "a@a.com" }, { "email": "a@c.com" }, { "email": "a@d.com" }]
I am allowing users email those who are in this json file; otherwise, I am throwing an error. The code for that is like this:
emailPasswordSignUpPOST: async function (input: any) {
try {
if (
originalImplementation.emailPasswordSignUpPOST ===
undefined
) {
throw Error('Should never come here');
}
const inputObject: any = {};
for (let index = 0; index < input.formFields.length; index++) {
const element = input.formFields[index];
inputObject[element.id] = element.value;
}
const { email, firstName, lastName, phoneNumber } = inputObject;
fs.readFile(usersFilePath, 'utf8', (error, data) => {
if (error) {
throw new HttpException(error.message, 500);
} else {
const users = JSON.parse(data);
const userEmails = users.map((user: any) => user.email);
if (!userEmails.includes(email)) {
throw new HttpException(
'You are not allowed to register.',
HttpStatus.BAD_REQUEST
);
}
});
let response: any = await originalImplementation.emailPasswordSignUpPOST(input);
response['user'] = {
...response['user'],
email,
firstName,
lastName,
phoneNumber,
};
return response;
} catch (error) {
throw new HttpException(
error.message,
HttpStatus.BAD_REQUEST
);
}
},
If I try to register with the wrong credentials, then it is throwing an error something like this: HttpException: You are not allowed to register.
and it shuts down the server (that is what I think is happening), which is expected, but then if I try to register with the correct credentials then it is not working. (Nothing ,no log at all)
How do I troubleshoot this server shut down?nkshah2
03/30/2023, 5:48 AMnkshah2
03/30/2023, 5:49 AMresponse
before you modify the user property?johnoliver2342
03/30/2023, 8:06 AM