TypeError: Cannot set property 'email' of undefined
Am working on a project using Nodejs and am trying to apply the password encryption but still getting this error "TypeError: Cannot set property 'email' of undefined". please can anyone help me? THANKS
var passport = require('passport');
var User = require('../models/user');
var LocalStrategy = require('passport-local').Strategy;
passport.serializeUser(function(user, done)
done(null, user.id);
);
passport.deserializeUser(function(id, done)
User.findById(id, function(err,user)
done(err, user);
);
);
passport.use('local.signup', new LocalStrategy(
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
, function(req, email, password, done)
User.findOne('email': email, function(err, user)
if(err)
return done(err);
if(user)
return done(null, false, message: 'Email is already in use');
var newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.encryptPassword(password);
newUser.save(function(err, result)
if(err)
return done(err);
return done(null, newUser);
);
);
));
javascript node.js
add a comment |
Am working on a project using Nodejs and am trying to apply the password encryption but still getting this error "TypeError: Cannot set property 'email' of undefined". please can anyone help me? THANKS
var passport = require('passport');
var User = require('../models/user');
var LocalStrategy = require('passport-local').Strategy;
passport.serializeUser(function(user, done)
done(null, user.id);
);
passport.deserializeUser(function(id, done)
User.findById(id, function(err,user)
done(err, user);
);
);
passport.use('local.signup', new LocalStrategy(
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
, function(req, email, password, done)
User.findOne('email': email, function(err, user)
if(err)
return done(err);
if(user)
return done(null, false, message: 'Email is already in use');
var newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.encryptPassword(password);
newUser.save(function(err, result)
if(err)
return done(err);
return done(null, newUser);
);
);
));
javascript node.js
newUser.local
is not defined.
– Teemu
Nov 14 '18 at 6:20
add a comment |
Am working on a project using Nodejs and am trying to apply the password encryption but still getting this error "TypeError: Cannot set property 'email' of undefined". please can anyone help me? THANKS
var passport = require('passport');
var User = require('../models/user');
var LocalStrategy = require('passport-local').Strategy;
passport.serializeUser(function(user, done)
done(null, user.id);
);
passport.deserializeUser(function(id, done)
User.findById(id, function(err,user)
done(err, user);
);
);
passport.use('local.signup', new LocalStrategy(
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
, function(req, email, password, done)
User.findOne('email': email, function(err, user)
if(err)
return done(err);
if(user)
return done(null, false, message: 'Email is already in use');
var newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.encryptPassword(password);
newUser.save(function(err, result)
if(err)
return done(err);
return done(null, newUser);
);
);
));
javascript node.js
Am working on a project using Nodejs and am trying to apply the password encryption but still getting this error "TypeError: Cannot set property 'email' of undefined". please can anyone help me? THANKS
var passport = require('passport');
var User = require('../models/user');
var LocalStrategy = require('passport-local').Strategy;
passport.serializeUser(function(user, done)
done(null, user.id);
);
passport.deserializeUser(function(id, done)
User.findById(id, function(err,user)
done(err, user);
);
);
passport.use('local.signup', new LocalStrategy(
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
, function(req, email, password, done)
User.findOne('email': email, function(err, user)
if(err)
return done(err);
if(user)
return done(null, false, message: 'Email is already in use');
var newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.encryptPassword(password);
newUser.save(function(err, result)
if(err)
return done(err);
return done(null, newUser);
);
);
));
javascript node.js
javascript node.js
edited Nov 14 '18 at 6:27
Chinedu Ernest
asked Nov 14 '18 at 6:17
Chinedu ErnestChinedu Ernest
61
61
newUser.local
is not defined.
– Teemu
Nov 14 '18 at 6:20
add a comment |
newUser.local
is not defined.
– Teemu
Nov 14 '18 at 6:20
newUser.local
is not defined.– Teemu
Nov 14 '18 at 6:20
newUser.local
is not defined.– Teemu
Nov 14 '18 at 6:20
add a comment |
2 Answers
2
active
oldest
votes
First, define newUser.local
then newUser.local.email
and password
.
var newUser = new User();
newUser.local = email:"", password:"";
newUser.local.email = email;
newUser.local.password = password;
newUser.save(function(err, result){
if(err)
return done(err);
add a comment |
local
is undefined. Try this:
var newUser = new User();
newUser.local =
email : email,
password : newUser.encryptPassword(password)
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
ThenencryptPassword
is not a function. Can’t say anything about that without seeing theUser
class
– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is calledencryptPassowrd
you callencryptPassword
which doesn’t exist
– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294176%2ftypeerror-cannot-set-property-email-of-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, define newUser.local
then newUser.local.email
and password
.
var newUser = new User();
newUser.local = email:"", password:"";
newUser.local.email = email;
newUser.local.password = password;
newUser.save(function(err, result){
if(err)
return done(err);
add a comment |
First, define newUser.local
then newUser.local.email
and password
.
var newUser = new User();
newUser.local = email:"", password:"";
newUser.local.email = email;
newUser.local.password = password;
newUser.save(function(err, result){
if(err)
return done(err);
add a comment |
First, define newUser.local
then newUser.local.email
and password
.
var newUser = new User();
newUser.local = email:"", password:"";
newUser.local.email = email;
newUser.local.password = password;
newUser.save(function(err, result){
if(err)
return done(err);
First, define newUser.local
then newUser.local.email
and password
.
var newUser = new User();
newUser.local = email:"", password:"";
newUser.local.email = email;
newUser.local.password = password;
newUser.save(function(err, result){
if(err)
return done(err);
answered Nov 14 '18 at 6:22
amiramir
9031026
9031026
add a comment |
add a comment |
local
is undefined. Try this:
var newUser = new User();
newUser.local =
email : email,
password : newUser.encryptPassword(password)
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
ThenencryptPassword
is not a function. Can’t say anything about that without seeing theUser
class
– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is calledencryptPassowrd
you callencryptPassword
which doesn’t exist
– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
|
show 2 more comments
local
is undefined. Try this:
var newUser = new User();
newUser.local =
email : email,
password : newUser.encryptPassword(password)
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
ThenencryptPassword
is not a function. Can’t say anything about that without seeing theUser
class
– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is calledencryptPassowrd
you callencryptPassword
which doesn’t exist
– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
|
show 2 more comments
local
is undefined. Try this:
var newUser = new User();
newUser.local =
email : email,
password : newUser.encryptPassword(password)
local
is undefined. Try this:
var newUser = new User();
newUser.local =
email : email,
password : newUser.encryptPassword(password)
answered Nov 14 '18 at 6:29
iPiratiPirat
1,492818
1,492818
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
ThenencryptPassword
is not a function. Can’t say anything about that without seeing theUser
class
– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is calledencryptPassowrd
you callencryptPassword
which doesn’t exist
– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
|
show 2 more comments
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
ThenencryptPassword
is not a function. Can’t say anything about that without seeing theUser
class
– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is calledencryptPassowrd
you callencryptPassword
which doesn’t exist
– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
It still didn't work, it now says: 'TypeError: newUser.encryptPassword is not a function'
– Chinedu Ernest
Nov 14 '18 at 6:46
Then
encryptPassword
is not a function. Can’t say anything about that without seeing the User
class– iPirat
Nov 14 '18 at 6:48
Then
encryptPassword
is not a function. Can’t say anything about that without seeing the User
class– iPirat
Nov 14 '18 at 6:48
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt-nodejs'); var userSchema = new Schema( email:type:String, required:true, password:type:String, required: true ); userSchema.methods.encryptPassowrd = function(password) return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null); ; userSchema.methods.validPassword = function(password) return bcrypt.compareSync(password, this.password); ; module.exports = mongoose.model('User',userSchema);
– Chinedu Ernest
Nov 14 '18 at 6:51
The method in Schema is called
encryptPassowrd
you call encryptPassword
which doesn’t exist– iPirat
Nov 14 '18 at 7:21
The method in Schema is called
encryptPassowrd
you call encryptPassword
which doesn’t exist– iPirat
Nov 14 '18 at 7:21
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
Yes! Yes! Yes!!! Thank you very much @iPirat, it works now. the error was i used 'encryptPassowrd' instead of 'encryptPassword' like you rightly said. Thanks Again.
– Chinedu Ernest
Nov 14 '18 at 7:37
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294176%2ftypeerror-cannot-set-property-email-of-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
newUser.local
is not defined.– Teemu
Nov 14 '18 at 6:20