Nightlife Coordination App - How to not search again after login?

Nightlife Coordination App - How to not search again after login?
0

#1

Hi everyone,

I am really stuck on this one. I made the Nightlige Coordination App with the MEAN stack. Authentication is with Passport JS. When you do a search and you login, it refreshes the page and deletes the results and you have to do the same search again. Anyone can help me how to make it not refresh/reload after login???

My Passport Routes:

var passport = require('passport');

var FacebookStrategy = require('passport-facebook').Strategy;

var session = require('express-session');

passport.serializeUser(function(user, done) {

done(null, user);

});

passport.deserializeUser(function(id, done) {

done(null, id);

});

app.get('/auth/facebook', passport.authenticate('facebook'));

app.get('/auth/facebook/callback', passport.authenticate('facebook', {

successRedirect: '/',
failureRedirect: '/error'

}));

My Angular code:

angular.module("popperooApp", ['ngRoute'])
  .config(function($routeProvider) {
    $routeProvider
      .when("/", {
        templateUrl: "list.html",
        controller: "ListController"
      })
      .otherwise({

        redirectTo: "/"

      });
  })
  .service("Venues", function($http) {

    this.getVenues = function(location) {

      var url = "search/" + location;

      return $http.get(url);

    };


  })
  .controller('ListController', function($scope, Venues) {

    $scope.searchLocation = function(location) {

      Venues.getVenues(location)
        .then(function(response) {

          $scope.venues = response.data;

        }, function(response) {

          alert("Error retrieving venues");

          console.log(response);

        });

    };

  })

I have tried several methods but none of it works for now.

Any help much appreciated?


#2

I see you are using Facebook’s login. Take a look at Facebook’s JavaScript SDK Login for logging in with a script instead of passport.


#3

I’m not sure how it works with PassportJS, but with Passwordless there is an optional origin object that you can pass around and it saves the origin url in the token store alongside the auth token.


#4

thanks for the feedback! I ended up using a ng-cookie, so I save the query and a boolean whether the user has searched yet or not, and reload the results after a login. Don’t know if there are any disadvantages of this method, but it works!


#5

@chemok78 - Hey, I’m stuck on the same part of the project, however I am not using Angular on this. So how did you get the page to show the same results after refresh when the user is authenticated?


#6

hi there, I used the build in Angular cookies to save the location query + if a user has searched yet or not. If so, it sends a request to the API after login and loads the search results. If you are not using Angular, you can maybe use the same logic?


#7

Since I am learning backend entirely here, I didn’t know any angular. I used passport, c9, ajax and the twitter authentication. One problem was that you can’t use twitter and cors, so stuck with the <a> tag. So I ended up setting a couple of cookies (could have used local storage) but never used cookies before so gave that a try. Had the <a call a function before doing the href. Then checked the cookies when the page loaded to see if this was the first load after the logon and if so was the location blank. Pretty sure this was not good practice, but it worked.