Search code examples
amazon-web-servicesamazon-cognitoaws-amplifyamplify-ios

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


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?


Solution

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

    Amplify.Auth.getCurrentUser() != nil