简体   繁体   中英

Where to put user logged in vs user logged out logic?

I know I'm doing this wrong.

When my app opens, I need to tell whether the user is logged in or logged out (and depending on that, open a different view controller).

My solution is in this image below.

在此处输入图片说明

I know this is wrong (it's just an empty View Controller for one function) but I don't know where else I could put this logic.

On top of this, I also need to know whether the user is a paid customer or a free customer (each gets a different home page). How do I check this too without building an entire new View Controller just for that purpose?

Edit

One comment asked me to paste my code, so here it is: ` import UIKit import Firebase

class CheckIfLoggedInViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    Auth.auth().addStateDidChangeListener { auth, user in
        if user != nil {
            // User is signed in. Show home screen
            self.performSegue(withIdentifier: "goToLoggedIn", sender: self)
        } else {
            // No User is signed in. Show user the login screen
            self.performSegue(withIdentifier: "goToLoggedOut", sender: self)
        }
    }

}

`

You can design this white screen same like launch screen. It is the general solution of this problem. When you done all your stuff (call apis, validation.. whatsoever) then navigate user to the required screen.

If your tasks are long then you can add some animations here, just like uber does. If you do not want any animation then make sure there is activity loader otherwise user assumes device is hanged due to your app.

How do I check this too without building an entire new View Controller just for that purpose?

When you app loaded in memory didFinishLaunchingWithOptions is called. If only you need to navigate user to either login or logout screen with condition then you can add code here.

But in this delegate, API call is not recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM