stayLoggedIn not working in REST API

Hi, I’m having a problem with keeping user logged in after page is reloaded. It simply doesn’t seem to work for me, I’ve added four different types of requisitions. One for registering new users, one for logging in to the existing users, one for validating the token which is returning true meaning the user exists and one to get the data from existing users. But for some reason when page is refreshed, the user data that should be returned to me, simply comes up with a null which was the type annotation I made if users don’t exist.

But as I said, it returns true to me in the token validation from the token that I saved in local storage, but when it comes to retrieving data itself it doesn’t work. I don’t know if I added stayLoggedIn correctly as I put this parameter in the body of login requisition, it is not completely clear this step in the documentation, and the other answers that I found were in other languages than JS with REST API so I didn’t understand correctly what should I do.

Hi Marcos,

When you use the REST API, your app sends a request and receives a response, which your app processes. The “stay logged in” functionality is a way to “remember” who the user is once they logged in. Remembering who the user is is done on the client side, i.e., your app. If you use the REST API, there is no SDK or any of our code. Therefore, it would be up to your application to remember the user (such as their user token) and re-use that token (if it is still valid) when the user returns to the app.

Had you used our SDK, then the implementation of remembering who the user is is available in the SDK itself; however, with the REST API, there is no Backendless code in your app at all.

Regards,
Mark

I handled it all myself in React as my application is using it, and so is the token value stored somewhere so it can be used again, up to this point I have no problem, I can sign new users, I can sign existing users, I can use the token, all normally, including the validation that is returning true when I have used the token stored, but my problem is that I can’t retrieve the existing data from users, such as their name, or email… How is it possible that the validation process is recognizing the token stored but can’t retrieve data from users when page is refreshed?

The validation logic checks if the token is valid.

If you need to get details about the user, that’s a different API call.

Thank you for your reply, turns out I could fix it by storing objectId to persistent localStorage also just as token, I thought I wouldn’t need to do this, but to get existing users I need objectId and it wasn’t letting me as I was trying to use again the POST method for login… it was my mistake of course, but also I think it would be simpler, if user could be get by using the token instead of objectId if it was possible adding this feature, I think the less information we add to localStorage it is better for security matters, but as in my application I am not using sensitive content so for me is okay in this, but it is a suggestion that I make.

Thank you for your assist truly!