#✅ - Unable to authenticate user and access s3 storage

14 messages · Page 1 of 1 (latest)

charred schooner
#

I couldn't authenticate user and access the files stored in s3. I have created a dummy user in the amazon cognito user pool
func signInUser() async{
do{
let result = try await Amplify.Auth.signIn(username: "dummy123", password: "admin123")
if result.isSignedIn {
print("user signed in successfully !")
}
else {
print("user not signed in !")
}

    }catch let error as AuthError{
        print("error while signing in : \(error)")
    }catch{
        print("unexpected error : \(error)")
    }
}
low timber
#

What's the error you're seeing?

charred schooner
low timber
#

Thanks. A couple of follow up questions:

  • Can you provide the code snippet where you're calling the Storage API?
  • Have you confirmed that your user is signed before calling the Storage API?
  • Please paste the contents of your amplifyconfiguration.json (redacting any values you'd like). Alternatively, you can run amplify diagnose --send-report and provide the Project Identifier. (more information on amplify diagnose can be found here: https://docs.amplify.aws/cli/reference/diagnose/)
charred schooner
#

alright sure

#

i didn't confirm if the user is signed in and i tried signing in new user based on the amplify studio docs but couldn't do it

#

//for downloading the data from s3

func downloadUSDZ(key: String) async{

    let options = StorageDownloadDataRequest.Options(accessLevel: .guest)
    let downloadTask = Amplify.Storage.downloadData(
        key: key,
        options: options
    )

    Task{
        for await progress in await downloadTask.progress{
            print("Progress :\(progress)")
        }
    }
    
    do {
        let data = try await downloadTask.value
        print("data : \(data)")
    }catch{
        print("error while loading data : \(error)")
    }
    
}
pallid knoll
#

i didn't confirm if the user is signed in and i tried signing in new user based on the amplify studio docs but couldn't do it

What do you see printed when you call the signInUser() method you previously shared?

charred schooner
#

it says "user pool client does not exist"
Recovery Suggestion: Make sure that the user pool has a requested resource

charred schooner
#

the data is stored in private s3 bucket

pallid knoll
#

As you are using a private s3 bucket, I assume that means you've configured it to only be accessible by authenticated users. But you are then attempting to access it without being authenticated, as your signInUser method fails.

There is likely an issue in your setup. Did you provision your AWS resources using the Amplify CLI, or are you importing existing resources?

Also, as aterian mentioned in his previous response, please provide your amplifyconfiguration.json contents (or run the diagnose command and provide the result).

charred schooner
#

okay i will send the diagonose file

silver cliffBOT
#

✅ - Unable to authenticate user and access s3 storage