AWS Amplify iOS: what is the most reliable way to find if a user is logged in

530 views Asked by At

Is it ok to check

Amplify.Auth.getCurrentUser() != nil

or should the app maintain a state variable and set that from this listener?

   _ = Amplify.Hub.listen(to: .auth) { payload in
        switch payload.eventName {
        case HubPayload.EventName.Auth.signedIn:
            // Update UI
            ....

If it's the latter, is that suppose to work even if the user logged in during one of the previous sessions?

1

There are 1 answers

1
rysv On BEST ANSWER

After further research and from Discord discussions looks like this is the best approach:

Amplify.Auth.getCurrentUser() != nil