User is nil when logging in

When a user creates an account, a few seconds after, we call:

let user = backendless?.userService.currentUser

It returns “nil”

Is there another function that we should be using to get the current user’s data? The reason we are doing this is to get the current user’s email and name.

Every 1 in 10 times this will work fine and return the correct user but almost every time it does not work.

Nevin, please clarify:

  1. Which kind of login did you use: simple login, easy…Login, loginWith…SDK?
  2. Did you use stayLoggedIn(true)?

we used login with Facebook SDK. Yes we used this line of code for that

self.backendless?.userService.setStayLoggedIn(true)

Please check if this issue persists if

self.backendless?.userService.setStayLoggedIn(false)

I am not even able to log in without it being set to true. There are other issues within the app that won’t let it run without it being set to true.

Can you also check the currentUser value right after the login? Maybe you need to set this object manually, having retrieved a user object by it’s persisted ID.