0
votes

I am new to Express and Parse. I am trying to make a simple modification to the Anyimg cloud tutorial. I would like to display the default home page only if the user is authenticated. If I use Parse.User.authenticated(), I get:

The error was TypeError: Object function (){e.apply(this,arguments)} has no method 'authenticated' at app.js:33:18 at main.js:1:1

Parse.User.current() compiles with no error, but the code does not work. What am I missing? I have tried literally over 60 different options over the last 3 days with no success.

I also tried to declare a GLOBAL from within user.js and that did not work. I did a require cloud/user from within app.js and that did not help at all.

I hope someone can help. It appears that Parse tutorials (outside parse.com) from about a year ago break.

On the other hand, I wanted to display the login page (not default) upon logout. I got it done in less than 10 minutes.

2
post your code, it will help understand things better. - Maddy
Hi Fosco, That is exactly the code I had (used a different boolean name though). However, I was trying to mess with globals and had declared the var at the top of the file/module. I moved that declaration within the function scope and now it all works. Thanks! - Cali Codr

2 Answers

1
votes

The correct way to do this would be:

var currentUser = Parse.User.current();
if (currentUser) {
  // logged in
} else {
  // not logged in
}

Parse.User.current() returns the current user, or undefined if not logged in.

as seen here: https://parse.com/docs/js_guide#users-current

0
votes

As mentioned above, I already had code that was similar to Fosco's. However, the var statement was not in the scope of the function as I was trying out o. I just moved it in and it all works. Thanks to everyone for looking into this.