Note that there are some explanatory texts on larger screens.

plurals
  1. POkeep getting "TypeError: Cannot read property 'publicUsername' of null" error
    primarykey
    data
    text
    <p>hey guys i have a function that validate a form before submitting into the database,however one of the field need to be unique so i have to send the data back to database to do comparison and if there's an error it will indicate user, else it will save the data into database. but i keep getting "TypeError: Cannot read property 'publicUsername' of null" and i don't know why </p> <h3> my code </h3> <pre><code> this.handleSignup = function(req, res, next) { "use strict"; var validate = validateSignup(req.body, function(error, data) { if(error) { res.send(400, error.message); } }); if(validate){ users.addUser(data, function(err, user) { sessions.startSession(data, function(err, session_id) { "use strict"; if (err) return next(err); res.cookie('session', session_id); res.send(200); }); }); } } </code></pre> <h3> validateSignup</h3> <pre><code>function validateSignup(data,callback) { "use strict"; users.checkPublicUsername(data.publicUsername, function(err, result){ if(result){ callback(new Error('Public Username is taken Please choose another'), null); } }); </code></pre> <h3>checkPublicUsername</h3> <pre><code> this.checkPublicUsername = function(data,callback) { var publicUsername = { "publicUsername":data } users.findOne(publicUsername, function(err, result) { if(result.publicUsername === data){//terminal show this line is the error callback(null,true); // if match return true to trigger indicator }else{ callback(null,false); // else return false to proceed } }) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload