Skip to content

TypeError: val.toString is not a function #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mafsan786git opened this issue Sep 13, 2019 · 6 comments
Closed

TypeError: val.toString is not a function #45

mafsan786git opened this issue Sep 13, 2019 · 6 comments
Assignees
Labels

Comments

@mafsan786git
Copy link

mafsan786git commented Sep 13, 2019

When I'm trying to log in it is throwing me the error...
here is error...

TypeError: val.toString is not a function
    at Object.escape (/home/mohd/Desktop/codebucket/loginsystem/node_modules/sqlstring/lib/SqlString.js:52:33)
    at Object.objectToValues (/home/mohd/Desktop/codebucket/loginsystem/node_modules/sqlstring/lib/SqlString.js:180:89)
    at Object.escape (/home/mohd/Desktop/codebucket/loginsystem/node_modules/sqlstring/lib/SqlString.js:54:26)
    at Object.format (/home/mohd/Desktop/codebucket/loginsystem/node_modules/sqlstring/lib/SqlString.js:100:19)
    at Connection.format (/home/mohd/Desktop/codebucket/loginsystem/node_modules/mysql/lib/Connection.js:274:20)
    at Connection.query (/home/mohd/Desktop/codebucket/loginsystem/node_modules/mysql/lib/Connection.js:192:22)
    at Strategy._verify (/home/mohd/Desktop/codebucket/loginsystem/config/passport.js:16:28)
    at Strategy.authenticate (/home/mohd/Desktop/codebucket/loginsystem/node_modules/passport-local/lib/strategy.js:88:12)
    at attempt (/home/mohd/Desktop/codebucket/loginsystem/node_modules/passport/lib/middleware/authenticate.js:361:16)
    at authenticate (/home/mohd/Desktop/codebucket/loginsystem/node_modules/passport/lib/middleware/authenticate.js:362:7)

AND MY LOG IN CODE IS GIVEN BELOWcan you please resolve this issue

const localStrategy = require('passport-local').Strategy;
const bcrypt = require('bcryptjs');
const mysql = require('mysql');

const connection = require('./database');

module.exports = function (passport) {
    passport.use(
        new localStrategy(
            {usernameField:'email',
            passwordField:'password',
            passReqToCallback:true
            },
            (email, password, done)=>{
                var sql = 'SELECT * FROM user WHERE email = ?';
                connection.query(sql,email,(error,results,fields)=>{
                    if(error) throw error;
                    //Match user
                    if(!results.length)
                        return done(null, false, {message:'That email is not register'});

                    //Match
                    bcrypt.compare(password,results[0].password,(err,isMatch)=>{
                        if(err) throw err;
                        if (isMatch) {
                            console.log(results[0]);
                            console.log('every thing is fine');
                            
                            //return done(null,results[0]);
                        }else{
                            return done(null, false, {message:'Password incorrect'});
                        }
                    });
                });
            })
    );

    //serializeuser
    passport.serializeUser(function (user,done) {
        console.log(user.id);
        done(null,user.id);
    });

    //deserializeuser
    passport.deserializeUser(function (id,done) {
        connection.query('SELECT * FROM user WHERE id = ?',id,(err,results,fields)=>{
            done(err,results[0]);
        });
    });

};
@dougwilson
Copy link
Member

Thanks for the report @mafsan786git . What steps do I need to take to be able to run that code above in order to reproduce the error?

@mafsan786git
Copy link
Author

mafsan786git commented Sep 13, 2019

Thanks for the report @mafsan786git . What steps do I need to take to be able to run that code above in order to reproduce the error?

can you please see this repository https://github.com/mafsan786git/LoginSystem @dougwilson

@dougwilson
Copy link
Member

Thank you. Anywhere I can find the steps to set up the app and then what to do to see the error in it?

@mafsan786git
Copy link
Author

mafsan786git commented Sep 13, 2019

Thank you. Anywhere I can find the steps to set up the app and then what to do to see the error in it?

signup using localhost:3000/app/register
Log in using localhost:3000/app/login

Thank you in advance

@dougwilson
Copy link
Member

Because you have passReqToCallback:true at https://github.com/mafsan786git/LoginSystem/blob/8c6b04818760ce55014925b1d27655b0e50961b7/config/passport.js#L12 the first agument to your callback is the request, not the email. Just remove that configuration.

@mafsan786git
Copy link
Author

Because you have passReqToCallback:true at https://github.com/mafsan786git/LoginSystem/blob/8c6b04818760ce55014925b1d27655b0e50961b7/config/passport.js#L12 the first agument to your callback is the request, not the email. Just remove that configuration.

Thank you for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants