How to get equivalent of “req.something” from in angular with nodejs

匆匆过客 提交于 2019-12-01 19:20:16

问题


I'm following a tutorial on how to set up authentication with nodejs and passport. (http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local)

The tutorial has me rendering templates with ejs and passing in flash data.

Instead of this, I'd like to use angularjs. The part I'm having trouble with is getting the flash data. I know how to use templates and send variables, but what in angular replaces the "req.flash('signupMessage')" in the below code?

This is the code the tutorial shows:

app.get('/signup', function(req, res) {
  // render the page and pass in any flash data if it exists
  res.render('signup.ejs', { message: req.flash('signupMessage') });    
});

This is the code where I set up my route

// public/js/appRoutes.js
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

$routeProvider

    // show signup form
    .when('/signup', {
        templateUrl: 'views/signup.html',
        controller: 'SignupController'  
    });
$locationProvider.html5Mode(true);

}]);

Here is the controller:

 // public/js/controllers/SetupCtrl.js
 angular.module('SignupCtrl', []).controller('SignupController', function($scope) {
     $scope.tagline = 'TEST';
 });

回答1:


A similar question was answered here: What is the proper way to log in users using Angular & Express?

TLDR: the answer posted was to the following link, where the author describes that you need to keep all the passport stuff on the server side, and then allow the client side (angular stuff) to request information about the session. http://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs



来源:https://stackoverflow.com/questions/25464798/how-to-get-equivalent-of-req-something-from-in-angular-with-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!