-
Notifications
You must be signed in to change notification settings - Fork 202
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
GraphQL Multi-Auth Not Working #3089
Comments
@dan-codes1 Thanks for opening the issue. Would you be able to share verbose logs and error that you are seeing? You can enable verbose logging to the console by doing this before calling
This will immensely help us narrow down our investigation. |
@harsh62 this is the log: <<<< FigByteStream >>>> FigByteStreamStatsLogOneRead: ByteStream read of 137,230 bytes @ 63,591 took 0.7807 sec. to complete, 2 reads >= 0.5 sec. successful amplify operation graphQLApi Creating loaded list of Favourite |
You |
@royjit I actually always added that but it was always overridden even after calling "api": { however even when i run Also, I get a new error: failed amplify operation graphQLApi with error: |
@dan-codes1 If you are changing the configuration file by hand, it will always get overridden during amplify pull/push. From the latest error it seems the graphQL API is not configured correctly. I would suggest to follow the guide to set up the category again and document each steps. If you still face an issue, please comment on the issue with all the steps you have documented and we will try to recreate the issue at our end. |
i have created a new api and even user pool and added multi auth to the API via cli. Multi auth is still not working and it still doesn't add the multi auth under plugins API section of the This is the documented cli step: ? Choose the default authorization type for the API API key
Edit your schema at /Users/danieleze/Documents/eemo/amplify/backend/api/eemo/schema.graphql or place .graphql files in a directory at /Users/danieleze/Documents/eemo/amplify/backend/api/eemo/schema |
Have the same problem since upgrading from Amplify v1 to v2. |
@tobias-feldmann oh so your multi with worked in v1 but stopped in v2? I started with v2 and mine has never worked. |
Yes exactly, with the same setup it worked with V1 @dan-codes1. I also deleted the Amplify project and created it again. The DatastorePlugin is configured like this:
|
This is a bit verbose, so i will try to summarize this in comment below. Here's my attempt to reproduce this problem, I'm currently using Amplify CLI version 12.2.3
The schema i used
When i run After this finished, the amplifyconfiguration.json file looks like this:
I ran Using SPM, I added
In the App's main file, ensure import SwiftUI
import Amplify
import AWSAPIPlugin
import AWSCognitoAuthPlugin
import AWSDataStorePlugin
@main
struct amplify3089App: App {
init() {
do {
Amplify.Logging.logLevel = .verbose
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.add(plugin: AWSAPIPlugin(modelRegistration: AmplifyModels()))
try Amplify.add(plugin: AWSDataStorePlugin(modelRegistration: AmplifyModels(),
configuration: .custom(authModeStrategy: .multiAuth)))
try Amplify.configure()
print("Amplify configured with DataStore, API, and Auth plugins!")
} catch {
print("Failed to initialize Amplify with \(error)")
}
}
var body: some Scene {
WindowGroup {
AppView()
}
}
} I created a user through the CLI:
The Back in the App, I established the DataStore subscriptions by calling Amplify.DataStore.start(), through a button func start() {
Task {
try? await Amplify.DataStore.start()
}
} Taking a look at the logs, I can see onCreate subscriptions that is created:
The subscription is established with owner field value of empty string. I believe this is the problem. It's establishing the subscription with the correct auth mode while the user is signed out (API Key), but the mutations are not being received by the client, because it's subscribed to a specific owner. For example, in the AppSync console, sending a mutation does not trigger a subscription event: On one window, using API Key, subscribe to the data with the empty owner field:
On a second window, using API Key, subscribe without owner field:
On a third window, using UserPool auth, logged in user, send a mutation:
Only the third (the mutation response of course) and second window (subscription without owner input specified) receives the mutation event:
From here, I'm curious how we are establishing the when the user is logged in from the App:
The subscription is established with an owner field of value "username". "username" is the username of the logged in user in the app. When i send a mutaton from the Appsync console with the logged in user (replay of the 3rd window above), i can see the mutation event come through on the app. Now, I logged in with another user and their mutations are not trigger subscription events. This seems to be expected since the subscription established is for a particular owner, the logged in user themselves. |
Let's take a look at the use case:
What is the expected behavior?
There seems to be 2 issues with DataStore. The first one is for a user that is not signed in, the subscriptions that are established is passing in owner input of empty string. This means that the read is specified for an empty owner, so no data is ever received on the API Key read-only use case. For APIKey auth, we should not be passing in "owner" input. The second issue is when the user is signed in, it's subscribing with an owner input of the logged in user, filtering down to only data created/updated/deleted by the user themselves (use case 1). Is this the expected behavior? Seems like DataStore should not pass in owner input in the subscription to achieve use case 3. |
Everything seems to be working well with
Make sure if you update the auth rules, Not signed in users, using API Key subscriptions, doesn't have owner field, which receives all mutations:
Signed In user, also using the above operation, and with the Authorization payload to be the token, is receiving all mutations. By not setting read access for |
@lawmicha Does this only work for datastore category? because I'm using the API category and its still not working. Im getting this error: Address Schema: Default auth = API Key. Secondary auth mode is cognito. |
Hey @dan-codes1, I can see in the response, the mutation failed because it's trying to send the mutation request using the API key. if you're making API calls using a different auth type from the primary auth mode, you'll have to modify the configuration as per #3089 (comment) to use the correct interceptors. The amplifyconfiguration.json currently only generates the primary auth mode, and is expected I believe. I understand you mentioned that the file gets overwriten on Ideally the solution we provide here a way to specify the auth type in code instead of the configuration file, where you can do something like this: Amplify.API.mutate(request: request, authtype: .cognitoUserPool) |
@lawmicha thanks it worked. However, though I rarely run Your suggestion Hope to see these improvements in future releases. |
@dan-codes1 please track/thumbs up this #3133 for the feature request of adding auth type. Since the original issue here is solved, please open an new issue if you face any other problems. @tobias-feldmann If you are still experienceing issues, please open a new issue with the details of your use case and schema. |
Describe the bug
My app does not work with multi-auth (API and CognitoPools) simultaneously. I have set my schema to accept multi auth but it still does not work. If I set the default auth mode to API, cognito stops working, and if I set the auth mode to cognito, Api stops working. For example:
With the schema above, I am unable to add a new To-Do or update/delete a To-Do after authenticating with cognito.
here is my API Plugin configuration for amplifyConfiguration.json
here is my APPSync configuration for awsConfiguration.json
Steps To Reproduce
Expected behavior
I expect it to allow owner to create update and delete
Amplify Framework Version
2.12.0
Amplify Categories
API
Dependency manager
Swift PM
Swift version
5.8
CLI version
12.1.1
Xcode version
14
Relevant log output
Is this a regression?
Yes
Regression additional context
No response
Platforms
No response
OS Version
MacOs Ventura
Device
iphone 14
Specific to simulators
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: