EDIT:
Thank you for your help ! You helped me pinpoint the problem and showed me the solution I was looking for: Accessing Express.js local variables in client side JavaScript
CODE:
index.ejs
$('.UpvoteButton').click(function () {
if (authdata == null) {
return res.redirect('/users/login');
}
else {
var $this = $(this);
var $other = $('.DownvoteButton');
if ($this.hasClass("on")) {
$this.removeClass("on");
} else if (!$this.hasClass('on') && $other.hasClass("on")) {
$this.addClass('on');
$other.removeClass("on");
} else {
$this.addClass('on');
}
}
});
app.js
//Global vars
app.use(function(req, res, next) {
res.locals.authdata = firebase.auth().currentUser;
next();
});
PROBLEM:
When I click, nothing happens. It worked before when I didn't have the if-else statement and the redirect statement.
N.B.: This is inside an EJS file. I am using Node.js.
QUESTION:
What have I done wrong ?