1

I'm using nodemailer to verify user's email when they sign up. It sends out an email with a link (something like localhost:3000/verify/?id=##).

When they click the link, it works and I can see a GET request has been made.

GET /verify/?id=141 200 2.582 ms - 4638

I tried this:

api.get('/verify/?id=', function(req, res) {
    console.log('verify request has been made'); // doesn't log on console
})

And I also tried this:

api.get('/verify', function(req, res) {
    console.log(req.query.id);
    console.log(req.param.id);
})

based on answers to questions I'd seen answered here and elsewhere, but nothing gets logged.

Also, I'm using Angular (with ngRoute) so it might be something going on on the frontend too, but I'm new to MEAN stack and don't know where to begin.

edit Here's the front-end:

app.routes.js

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

  $routeProvider
    .when('/', {
      templateUrl: 'app/views/pages/map.html',
      controller: 'MainController',
    })
    .when('/verify/:username', {
      templateUrl: 'app/verify/verify.html',
      controller: 'verifyController'
    })
  $locationProvider.html5Mode({ enabled: true, requireBase: false });;
})

verifyController.js

angular.module('verifyController', ['verifySerivice'])
  .controller('verifyController', function($routeParams, verify){
      console.log('in verify controller');
      var id = $routeParams.id;
      verify.verifyUser(id);
})

verifyService.js

angular.module('verifyService', [])

  .factory('verify', function($http) {

    var verifyFactory = {};

    verifyFactory.verifyUser = function(id) {
      console.log('verify service accessed');
      return $http.get('/verify', id)
        .then(handleSuccess, handleError);
    }

    return verifyFactory;
  })
2
  • Are you getting 404 or getting undefined query value? Commented Oct 11, 2016 at 18:51
  • I'm not getting a 404. It's not saying anything is undefined either, but none of the console.log statements are executed. Commented Oct 11, 2016 at 19:22

1 Answer 1

1

Can you provide the routing code and the code you are using to make the request? If Angular is handling your routing, the request may never actually make it to the Node server if you are requesting the URL through the address bar of the browser. If you are using the http module to make a get AJAX request, that would be helpful as well to see.

Sign up to request clarification or add additional context in comments.

3 Comments

Based on just a quick look, it seems you are using the angular http.get incorrectly. It expects a path as the first param and a config object as the second: docs.angularjs.org/api/ng/service/$http#get
I think you will need to concatonate the id onto the path, so http.get("verify?id="+id, configObject). Also, just try throwing a console log of "Testing" in the node route to see if it is getting hit at all.
Thanks! That got things working on the front end at least. Now to jank it to the backend....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.