Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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';
 });
like image 787
Shane Drye Avatar asked Nov 10 '22 03:11

Shane Drye


1 Answers

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

like image 122
Tymotheos Szulc Avatar answered Nov 14 '22 22:11

Tymotheos Szulc