Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Amplify v2 fetchAuthSession returns isSignedIn False in Swift : After migrating Amplify v1 to v2 in iOS Swift, on app reopening #3604

Open
anand-OSM opened this issue Apr 10, 2024 · 5 comments
Assignees
Labels
auth Issues related to the Auth category bug Something isn't working

Comments

@anand-OSM
Copy link

anand-OSM commented Apr 10, 2024

Describe the bug

After migrating AWS Amplify v1 to v2 in our Swift App, we've encountered a persistent issue with the session. Despite successful config and login, I think the authentication state is not preserved upon reopening the app.
I am using Swift and SwiftUI and Cognito HostedUI for login/Signup

Amplify.Auth.fetchAuthSession always returns isSignedIn false

Below is my simple code :

Configure Amplify

func configureAmplify () {
        do {
            try Amplify.add(plugin: AWSCognitoAuthPlugin())
            try Amplify.configure()
            //print("Amplify configured successfully")
        } catch {
            //print("Failed to initialize Amplify with \(error)")
        }
    }

Fetch session

    Task {
        
        do {
            let session = try await Amplify.Auth.fetchAuthSession()
            if session.isSignedIn {
                // print("User signed in : \(session.isSignedIn)")
            } else {
                // print("User signed in:\(session.isSignedIn)")
            }
        } catch let error as AuthError {
            // print("Fetch auth session failed with error - \(error)")
        } catch {
            // print("Unexpected error: \(error)")
        }
    }

Steps To Reproduce

Steps to reproduce the behavior:
1. Open the app and login with Hosted UI
2. Fetch the session using Amplify.Auth.fetchAuthSession() 
3. Check the isSignedIn, it returns true
4. Close the app and remove from the background 
5. Reopen the app, call Amplify.Auth.fetchAuthSession() from @main App init() {}
6. Check the isSignedIn flag (its coming as false)

Expected behavior

Once signed in whenver open app
Amplify.Auth.fetchAuthSession should always returns isSignedIn false

Amplify Framework Version

2.27.1

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5

CLI version

12.10.1

Xcode version

15.2

Relevant log output

<details>
<summary>Log Messages</summary>


INSERT LOG MESSAGES HERE
```

Is this a regression?

Yes

Regression additional context

I was using Amplify v1 and it was working fine, persisted the session and return true untill I log out.
When I migrated from V1 to V2, I started facing this issue.

Platforms

iOS

OS Version

iOS 16 & iOS 17

Device

iPhone 8 and above

Specific to simulators

No response

Additional context

No response

@anand-OSM anand-OSM changed the title Amplify v2 fetchAuthSession returns isSignedIn False when app reopening | after migrating Amplify v1 to v2 in iOS Swift Amplify v2 fetchAuthSession returns isSignedIn False : when app reopening | after migrating Amplify v1 to v2 in iOS Swift Apr 10, 2024
@anand-OSM anand-OSM changed the title Amplify v2 fetchAuthSession returns isSignedIn False : when app reopening | after migrating Amplify v1 to v2 in iOS Swift Amplify v2 fetchAuthSession returns isSignedIn False : after migrating Amplify v1 to v2 in iOS Swift, on app reopening | Apr 10, 2024
@anand-OSM anand-OSM changed the title Amplify v2 fetchAuthSession returns isSignedIn False : after migrating Amplify v1 to v2 in iOS Swift, on app reopening | AWS Amplify v2 fetchAuthSession returns isSignedIn False : After migrating Amplify v1 to v2 in iOS Swift, on app reopening | Apr 10, 2024
@anand-OSM anand-OSM changed the title AWS Amplify v2 fetchAuthSession returns isSignedIn False : After migrating Amplify v1 to v2 in iOS Swift, on app reopening | AWS Amplify v2 fetchAuthSession returns isSignedIn False : After migrating Amplify v1 to v2 in iOS Swift, on app reopening Apr 10, 2024
@anand-OSM anand-OSM changed the title AWS Amplify v2 fetchAuthSession returns isSignedIn False : After migrating Amplify v1 to v2 in iOS Swift, on app reopening AWS Amplify v2 fetchAuthSession returns isSignedIn False in Swift : After migrating Amplify v1 to v2 in iOS Swift, on app reopening Apr 10, 2024
@phantumcode
Copy link
Member

@anand-OSM Thanks for submitting the issue. We will try to reproduce the issue and investigate further.

@phantumcode phantumcode added bug Something isn't working auth Issues related to the Auth category labels Apr 10, 2024
@anand-OSM
Copy link
Author

Anything on this @phantumcode

@phantumcode
Copy link
Member

phantumcode commented Apr 15, 2024

@anand-OSM I have not been able to reproduce this issue. I was able to fetch a signed in auth session after migrating from Amplify V1 to Amplify V2. Closing and re-opening the app several times also resulted in a successful auth session on each app reopening.

Can you specify what version of Amplify V1 are you migrating from? If possible, are you able to reproduce the issue with a basic test app or sample app that demonstrates your code usage?

@phantumcode phantumcode added the pending-response Issue is pending response from the issue requestor label Apr 17, 2024
@anand-OSM
Copy link
Author

@phantumcode its v1.30.9
I was using cocoa pod , but now as v2 doesn't support cocoapod , I'm using SPM

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue requestor label Apr 22, 2024
@harsh62
Copy link
Member

harsh62 commented May 2, 2024

The issue is being discussed on discord with the customer. We will post an update here once we have more data to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants