Searching for user before login results in error 3064

Hi,
I have updated the Backendless Api via Cocoapods yesterday (latest version) and since then when I try to check if a user exist (before allowing registration) I get a 3064 error user token does not exist. This only happens on iOS 10 device.
Could you please look in to this as it just happened randomly since the last update.
Thanks

Does the error happen if you try calling the “logout” method first (to clear the user token), then check if the user exists?

Hi Mark,

No, not immediately before, but a user would have to logout before another user can use the app to register, that being said I did try deleting the app and compiling again and it worked. Now I am guessing that since I do not allow multiple logins, when the user does login on another device they will be logged out but not properly i.e. their token is still available on this device, am I right? Could that be the reason? If so then I would assume that your suggestion of performing a logout first would work?

Thanks

Hi Mu,

It looks like the option “Enable Multiple Logins” of your Backendless app is OFF:
http://support.backendless.com/public/temp/5a6a059c317dbff49e891faad39e6bf4.png</img>

So, if you use stayLoggedIn, you can meet with following situation:

  1. You have logged in on the first device (simulator) and got an active user token.
  2. Then you logged in with the same email (or another entity) from second device (simulator). So, with OFF state of “Enable Multiple Logins” option your first user token becomes inactive, and all your calls will receive 3064 error. In this case you need to logout. Another way is set ON for “Enable Multiple Logins” option.

Here is a code which demonstrates how you could use stayLoggedIn mode properly:

    func logoutUser() {
        
        Types.tryblock({ () -> Void in
            
            self.backendless!.userService.logout()
            let user = self.backendless!.userService.currentUser
            print("User has been logged out (SYNC): \(user)")
            },
                       
            catchblock: { (exception) -> Void in
                print("logoutUser: server reported an error: \(exception as! Fault)")
        })
    }
    
    func stayLoggedIn(email: String, password: String) {
        
        Types.tryblock({ () -> Void in
            
            if self.backendless!.userService.isStayLoggedIn {
                
                print("isValidUserToken will be checked")
                
                if self.backendless!.userService.isValidUserToken().boolValue {
                    let user = self.backendless!.userService.currentUser
                    print ("User has been STAY logged in: \(user))")
                    return
                }
                
            }
            else {
                self.backendless!.userService.setStayLoggedIn(true)
            }
            
            print("User NEED to be logged in")
            
            let user = self.backendless!.userService.login(email, password: password)
            print("User has been logged in (SYNC): \(user)")
            },
                       
            catchblock: { (exception) -> Void in
                print("stayLoggedIn: server reported an error: \(exception as! Fault)")
                self.backendless!.userService.setStayLoggedIn(false)
                self.logoutUser()
            }
        )
    }

Thanks for your detailed reply,

I understand what is happening now, if there are any tokens remaining from a previous session I will just do a log out to remove them.

Thanks again

Hi again,

We only managed to work on this recently and something seems strange, even when trying to do a logout the error still appears!
It would’ve been okay if we only wanted to re login the user (I could just redirect them) but when a new user wants to register we check to make sure the same email address doesn’t exist in the database and that check also throws in this error, which effectively renders the app useless.

Please could you provide the mechanism for just clearing the user token? Or is there any other ways in which this (checking existing emails) can be achieved?

Thanks for your help

p.s I am using Objective-C