cordova - phonegap ajax user authentication with nodejs-expresss-mongo-passportjs -
i have built basic node.js user authentication system based on node.js, express.js, passport-local.
i store username , passwords in mysql database , use mongo persistent storage sessions. want move user registration , login phonegap.
from tutorials have found online, way seems work is ajax user authentication. have 2 questions:
how rewrite express routes respond json since passport.js relies on redirects?
// process signup form app.post('/register', passport.authenticate('local-signup', { successredirect : '/home', failureredirect : '/register', failureflash : true // allow flash messages }));
// process login form app.post('/login', passport.authenticate('local', { successredirect : '/home', failureredirect : '/login', failureflash : true // allow flash messages }));
and in strategies have :
passport.use('local-signup', new localstrategy({ usernamefield : 'email', passwordfield : 'password', passreqtocallback : true }, function(req, email, password, done) { ... rest of code queries dbalso login
//configure passport local strategy login passport.use(new localstrategy( function(username, password, done) { var query = 'select * users email = '+ connection.escape(username); connection.query(query, function (err, user) { if (err) { return done(err); ... rest of code }
2.will ajax authentication in phonegap work sending post '/login' , therefore creating new active session in express server?
3.how handle state in client. in normal webapp use redirects ie. failed login attempts, logout, etc. in ajax authentication how handle that? return status code, return new markup, update part of view?
i close question did research , original problem lack of understanding of how phonegap apps architected. wasn't aware need follow single page app architecture vs traditional web page model.
Comments
Post a Comment