GithubHelp home page GithubHelp logo

Comments (8)

stefanbuck avatar stefanbuck commented on July 20, 2024

Hi @geekhack
can you provide me your source code to help me allocate your problem exactly?

from sails-social-auth-example.

geekhack avatar geekhack commented on July 20, 2024

Hi @stefanbuck
my user model:

module.exports = {

adapter: 'mysql',
tableName: 'user',
migrate: 'safe',
schema: true,  //this only saves the available atributes and discards the rest that are not available


attributes  : {
    provider: {
        type:'STRING',
        unique:true
    },

    uid: 'INTEGER',
    name: 'STRING',
    email: 'STRING',
    firstname: 'STRING',
    lastname: 'STRING',

    autoPK:false

}

};

//my middleware.js verifyHandler

var verifyHandler = function (token, tokenSecret, profile, done) {
process.nextTick(function () {

    User.findOne({uid: parseInt(profile.id)}).done(function (err, user) {
            if (user) {
                //return done(null, user);
                console.log(profile);
               //this returns the object ..okay
            } else {

                var data = {
                    provider: profile.provider,
                    uid: profile.id,
                    name: profile.displayName
                };

                if(profile.emails && profile.emails[0] && profile.emails[0].value) {
                    data.email = profile.emails[0].value;
                }
                if(profile.name && profile.name.givenName) {
                    data.firstname = profile.name.givenName;
                }
                if(profile.name && profile.name.familyName) {
                    data.lastname = profile.name.familyName;
                }

                User.create(data).done(function (err, user) {
                        return done(err, user);
                    });
            }
        });
});

};

from sails-social-auth-example.

stefanbuck avatar stefanbuck commented on July 20, 2024

@geekhack it's really strange. Your code works fine on my machine with a little modification in the if statement block. But i'm not sure if this is your problem. You musst call the return done(null, user); to send the result back to the controller.

I use the following version of sails and mySQL:
sails: 0.9.16
mySQL: 5.5.25

from sails-social-auth-example.

geekhack avatar geekhack commented on July 20, 2024

Inserting the data into the datastore is not the issue.I have tried your suggesting and is still duplicating records.I have created a repo here.You can have a look at it and advise.
https://github.com/geekhack/sailsfB.git

from sails-social-auth-example.

geekhack avatar geekhack commented on July 20, 2024

@stefanbuck I have used the method User.find().where({uid: profile.id}).done and seems to find the user, now the only issue is that it cannot serialize the session(seems to be a sessions issue)..Any idea on mysql sessions?

from sails-social-auth-example.

stefanbuck avatar stefanbuck commented on July 20, 2024

I tried to reproduce your issue without success!? This is how my mySQL dump looks like.

INSERT INTO `Sessions` (`sid`, `expires`, `json`, `id`, `createdAt`, `updatedAt`) VALUES
('tIReU0cKMHj4Ku07Vv-uD4XY', 1397682103, '{"cookie":{"originalMaxAge":900000,"expires":"2014-04-16T21:01:43.438Z","httpOnly":true,"path":"/"},"passport":{"user":1393946}}', 1, '2014-04-16 22:46:38', '2014-04-16 22:46:43');

from sails-social-auth-example.

geekhack avatar geekhack commented on July 20, 2024

Its ok.thanks.I am sure there is a way,I will figure it out and get back to you. :)

from sails-social-auth-example.

geekhack avatar geekhack commented on July 20, 2024

Hey @stefanbuck .I solved the issue.It was not about session store,but about the data type in the mysql database.Just use varchar on the datatype column and make sure you change your user model attribute(uid) to string.Finally ensure you have changed the middleware findOne method to:

User.findOne({uid: profile.id}).done(function (err, user) {

Omitting parseInt.
Thanks and Cheers!

from sails-social-auth-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.