angularjs - Passport.js route not redirecting -
angularjs - Passport.js route not redirecting -
update: using different path successredirect have managed 200 response request (see code below). true first time nail route, though. so, browser not alter page rendered. i.e. after register dummy user, there no actual redirect.
after more research code 304 , playing seems caching issue, that's far i've gotten far.
get /test
app.get('/test', function(req, res) { res.render('video-view.html'); }); // process signup form app.post('/signup', passport.authenticate('local-signup', { successredirect : '/test', // redirect secure profile section failureredirect : '/sign-up', // redirect signup page if there error failureflash : true // allow flash messages }));
i'm having lot of problem getting router redirect after successful local signup. /config/passport.js file adds row database , appears serialize session. returns user router, attempts redirect browser. looking @ console requests, see unsuccessful request: /home 304.
i've been working @ quite while , haven't been able find solution or prepare problem. part of issue i'm not using templating engine - serving html scripted angular.js. maybe haven't configured properly, other routing , functionality working well. thoughts?
here router code:
var express = require('express'); module.exports = function(app, passport) { app.get('/signup', function(req, res) { // render page , pass in flash info if exists res.render('sign-up.html'); }); app.get('/home', function(req, res) { res.render('video-view.html'); }); app.post('/signup', passport.authenticate('local-signup', { successredirect : '/home', // redirect secure profile section failureredirect : '/signup', // redirect signup page if there error failureflash : true // allow flash messages }));
};
my server set this:
var express = require('express'); var app = express(); var port = process.env.port || 8080; var passport = require('passport'); var flash = require('connect-flash'); require('./config/passport')(passport); // pass passport configuration app.configure(function() { app.use(express.logger('dev')); // log every request console app.use(express.cookieparser()); // read cookies (needed auth) app.use(express.bodyparser()); // info html forms app.engine('html', require('ejs').renderfile); app.use('/', express.static(__dirname + '/views')); app.use(express.session({ secret: 'vidyapathaisalwaysrunning' } )); // session secret app.use(passport.initialize()); app.use(passport.session()); // persistent login sessions app.use(flash()); // utilize connect-flash flash messages stored in session }); require('./app/routes.js')(app, passport); // load our routes , pass in our app , configured passport app.listen(port);
resolved: issue caused code in view, surprisingly.
here technique before , after:
before using angular.js below. sign-up.html
<div class="col-xs-6" id="register"> <p> come in username </p> <input type="text" ng-model="username"/> <p> come in password </p> <input type="text" ng-model="password"/> <input type="button" ng-click="register()"> </div>
controller.js
$scope.register = function(){ var send = {'username': $scope.username, 'password': $scope.password}; $http.post('/signup', send); };
i believe reason didn't work browser did not know wait response node. not positive best guess problem solved promises in angular.
i solved redirect issue leaving angular out of equation , handling post form in html. here working code no changes server-side:
sign-up.html
<form action="/signup" method="post"> <input type="text" name="username" /> <input type="text" name="password" /> <button type="submit" id="enter" value="enter" /> </form>
angularjs node.js express passport.js
Comments
Post a Comment