Support Topics Documentation Slack YouTube Blog

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?

Hi,

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

    • App Delegate (set stay logged in = true)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
 // Override point for customization after application launch.
 backendless?.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
 backendless?.userService.setStayLoggedIn( true )
 
 return true
 }
    • Login View Controller
 func backendlessLogin(email:String, password:String) {
 
 backendless?.userService.login(
 email, password: password,
 response: { (registeredUser : BackendlessUser?) -> () in
 print("User has been logged in (ASYNC): \(registeredUser)")
 //go to next view
 },
 error: { (fault : Fault?) -> () in
 print("Server reported an error: \(fault)")
 //send alert to user
 }
 )
 }
    • Logout from another view
func logout() {
 self.showLoadingScreen()
 backendless?.userService.logout(
 { ( user : Any?) -> () in
 print("User logged out.")
 //go back to login view
 },
 error: { ( fault : Fault?) -> () in
 print("Server reported an error: \(fault)")
 })
 }
    • In viewDidLoad for LoginViewController
backendless?.userService.isValidUserToken(
 { (result : Any?) -> () in
 print("isValidUserToken (ASYNC): \(result)")
 //go to next view
 },
 error: { (fault : Fault?) -> () in
 print("Server reported an error (ASYNC): \(fault)")
 } 
 )

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

if backendless?.userService.currentUser != nil {
 go to next screen
 print("persisted")
 }else{
 print("failed persist")
 }

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

Cheers mate :slight_smile:

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

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

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

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

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.