Backendless Support
 
In Progress

Persistent Login - Logout

After logging in using: backendless?.userService.setStayLoggedIn( true ) in the app delegate,

and classic login: backendless?.userService.login(

email, password: password,

response: { (registeredUser : BackendlessUser?) -> () in

I try to logout using classic logout - then return to the login screen.

I have a check that is called from the viewDidLoad method to check for any valid user tokens: backendless?.userService.isValidUserToken(

{ (result : Any?) -> () in

However, it always returns true even after a logout.

Why does this happen?

Leave a Comment

Comments (7)

photo
1

Hi,

Can you please prepare a minimal verifiable sample, which would reproduce the problem?

photo
1

1. - App Delegate (set stay logged in = true)

  1. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  2. // Override point for customization after application launch.
  3. backendless?.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
  4. backendless?.userService.setStayLoggedIn( true )
  5. return true
  6. }

2. - Login View Controller

  1. func backendlessLogin(email:String, password:String) {
  2. backendless?.userService.login(
  3. email, password: password,
  4. response: { (registeredUser : BackendlessUser?) -> () in
  5. print("User has been logged in (ASYNC): \(registeredUser)")
  6. //go to next view
  7. },
  8. error: { (fault : Fault?) -> () in
  9. print("Server reported an error: \(fault)")
  10. //send alert to user
  11. }
  12. )
  13. }

2. - Logout from another view

  1. func logout() {
  2. self.showLoadingScreen()
  3. backendless?.userService.logout(
  4. { ( user : Any?) -> () in
  5. print("User logged out.")
  6. //go back to login view
  7. },
  8. error: { ( fault : Fault?) -> () in
  9. print("Server reported an error: \(fault)")
  10. })
  11. }

4. - In viewDidLoad for LoginViewController

  1. backendless?.userService.isValidUserToken(
  2. { (result : Any?) -> () in
  3. print("isValidUserToken (ASYNC): \(result)")
  4. //go to next view
  5. },
  6. error: { (fault : Fault?) -> () in
  7. print("Server reported an error (ASYNC): \(fault)")
  8. }
  9. )

4.2 - Have also tried this (in place of 4)

  1. if backendless?.userService.currentUser != nil {
  2. go to next screen
  3. print("persisted")
  4. }else{
  5. print("failed persist")
  6. }

photo
1

Thanks! We shall test this approach and notify you about the results.

photo
1

Cheers mate :)

photo
photo
1

Any news on this so far? - Would appreciate a default project in Swift 3 with this working if my bug is non-reproduceable :)

photo
1

Found a workaround that I'm using right now. I place this line just before I call the default logout function:

  1. self.backendless?.userService.setStayLoggedIn(false) //required as workaround for logout

    backendless?.userService.logout( .....//responder/error

photo
1

I've created an internal task to investigate this, the task ID is BKNDLSS-13867. We shall notify you as soon as we have any news.