node.js - ExpressJS app login fails after saving first login history -
i've implemented expressjs app using passportjs, mongodb (mongoose) , json web tokens.
inside successful login route implementation
await user.insertlogintime(); const token = user.generatejwt(); res.status(200).json({ token });
mongoose model method 'insertlogintime'
userschema.methods.insertlogintime = async function() { try { const presenttime = new date().gettime(); await this.loginhistory.push(presenttime); await this.save(); return; } catch (error) { throw new error(error); } };
first login successful , 'postman' receives token returns invalid password error on next attempts.
removing 'insertlogintime' method logs-in on multiple attempts. there mistake in 'insertlogintime' implementation?
i've resolved issue. occurring because added password hashing schema 'pre' hook 'save'. on saving login history, hashed password being hashed again , saved back. deleting actual password hash , causing next attempts fail.
Comments
Post a Comment