Open MatthieuTnsc opened 4 years ago
@MatthieuTnsc did you solve it? I'm getting the same error. My questions is that I should validate
if (req.body.body.trim() === '') {
return res.status(400).json({ body: 'Body must not be empty' });
}
on the post for creating screams.
Hi @fernandovch no I didn't. I had the same behavior each time I had to use the .trim(). I removed it from the validation functions to keep on moving with the tutorial..
Are you sure that string
isnt returning as undefined
?. Sometimes, this error is caused by this.
Try to prevent this error from occurring.
I tried so many different options for 3 days. Did not get the correct answer
I also got the same error at some point. But I solved it. The type undefined means the string is not getting a value when it's been called. When it's been called from login make sure the valid data is passed. Sometimes the variables aren't assigned properly. upload you repo here on github maybe i can help.
Hi Thilanka, this is the code for adding user details
exports.addUserDetails = (req, res) => { let userDetails = reduceUserDetails(req.body); db.doc(
/users/${req.user.handle}).update(userDetails) .then(() => { return res.json({message: 'Details added successfully'}) }) .catch(err => { console.error(err); return res.status(500).json({error: err.code}) }); }
and this is the code for reducing data
exports.reduceUserDetails = (data) => { let userDetails = {}; if(!isEmpty(data.bio.trim())) userDetails.bio = data.bio; if(!isEmpty(data.location.trim())) userDetails.location = data.location; return userDetails; }
Hi Thilanka, this is the code for adding user details
exports.addUserDetails = (req, res) => { let userDetails = reduceUserDetails(req.body); db.doc(
/users/${req.user.handle}).update(userDetails) .then(() => { return res.json({message: 'Details added successfully'}) }) .catch(err => { console.error(err); return res.status(500).json({error: err.code}) }); }
and this is the code for reducing dataexports.reduceUserDetails = (data) => { let userDetails = {}; if(!isEmpty(data.bio.trim())) userDetails.bio = data.bio; if(!isEmpty(data.location.trim())) userDetails.location = data.location; return userDetails; }
could you put the console log as well? also if it's possible upload yourcode here on github as a repo. install git then change in to code folder.
git init
git add .
git commit -m "Initial commit"
git remote rename origin old-origin
git remote add origin https://github.com/your-github-username/your-git-repo.git
git push -u origin --all
https://github.com/TurboJapuraEfac/FirebaseBackend This is the repository. Add user information is the part that is involved with this issue.
TypeError: Cannot read property 'trim' of undefined at exports.reduceUserDetails
This is how I passed data from postman to test whether data is added { "bio" : "Kumar Sangakkara ", "website" : "user.com", "location " : "London, UK" }
Check file validators.js line 43 and 44.
const userDetails = {};
if (!isEmpty(data.bio.trim())) userDetails.bio = data.bio;
if (!isEmpty(data.website.trim())) {
you are sending a string which is already trimmed.
const isEmpty = (string) => {
if (string.trim() === '') return true;
else return false;
};
Thank you Thilanka. It was a error when passing the data from PostMan. Thank you so much. I ran the server locally and found the error.
I deployed your project to firebase and was just trying out the function. Glad you were able to find out the error. I finished part 9 of the youtube series a few minutes ago.
On Thu, Jun 25, 2020 at 10:08 PM Buddhika Weerasinghe < notifications@github.com> wrote:
Thank you Thilanka. It was a error when passing the data from PostMan. Thank you so much. I ran the server locally and found the error.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hidjou/classsed-react-firebase-functions/issues/17#issuecomment-649679446, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQBIJG77ZELZLFFCH7ZXTRYN4O7ANCNFSM4NC3W3KA .
--
Hi, I am following the YouTube tutorial (amazing job 👍)
I am at the stage of building the signup and login validation functions. When I POST a signup request with an empty value I've got an TypeError due to the trim function used in the 'isEmtpy' helper.
Any idea how to fix it?
Thanks