Unauthenticated owner in GraphQL
Note: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum
Which Category is your question related to? AWS Amplify Multi-Auth GraphQL
Amplify CLI Version 4.18.1
What AWS Services are you utilizing? auth graphql api
Usage Question I want to allow an unauthenticated user to mutate and read a shopping cart where they can add the products they want. This cart is unique for each user. Therefore the cart can only be treated and read by the owner who created it.
I currently use 2 user providers. userPools for authenticated users. And IAM for users without authentication. The problem comes from that the unauthenticated users have no way to distinguish their created cart. Therefore, any unauthenticated user can see the carts of others owners.
Looking at the documentation, it seems that only the Owner functionality is provided for the userPool provider. https://docs.amplify.aws/cli/graphql-transformer/directives#allowed-authorization-mode-vs-provider-combinations

- How could I emulate this feature for unauthenticated guest users?
- Should I use the userPool provider to create temporary accounts as soon as the unauthenticated user enters the application for the first time? 2.1. Then when the user wants to create an account, what procedure would have to be followed to transfer the information from that temporary account to a final one? 2.2 Or instead I should only update the temporary account with the new data without creating another account.
Thank you!!
Provide additional details e.g. code snippets
type Cart
@model(subscriptions: null)
@auth(
rules: [
# The owner is allowed to do everything
{ allow: owner }
# Admin users can access any operation.
{ allow: groups, groups: ["Admin"] }
# Guest users can do everything
{ allow: public, provider: iam, operations: [read, create, update, delete] }
])
{
id: ID!
totalPrice: Float
createdAt: AWSDateTime!
closedAt: AWSDateTime
cartItems: [CartItem] @connection(keyName:"byCart", fields: ["id"])
}
I would recommend using a separate model for Cart of unauth customers and storing all the items there before they signin in. Allowing public access to the cart type could allow others UnAuth users could cause security issues in future.
Transferring of content of cart from Cart as soon as the user signs in could be handled by post authentication lambda trigger, and you could pass the the temporary cart information (such as cartId) as metadata to your SignIn method call
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.