aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

User is unauthorized to query sync... with auth mode userPool Error coming up randomly #13703

Closed Gaztoof closed 3 months ago

Gaztoof commented 3 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

DataStore

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

``` # Put output below this line System: OS: Windows 10 10.0.19045 CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz Memory: 24.79 GB / 47.94 GB Binaries: Node: 20.15.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.3636.0), Chromium (127.0.2651.74) Internet Explorer: 11.0.19041.3636 npmPackages: %name%: 0.1.0 @aws-amplify/backend: ^1.0.4 => 1.0.4 @aws-amplify/backend-cli: ^1.2.1 => 1.2.2 @aws-amplify/react-native: ^1.1.4 => 1.1.4 @aws-amplify/ui-react: ^6.1.14 => 6.1.14 @aws-amplify/ui-react-internal: undefined () @aws-amplify/ui-react-native: ^2.2.3 => 2.2.3 @aws-amplify/ui-react-storage: ^3.1.6 => 3.1.6 @babel/core: ^7.20.0 => 7.25.2 @babel/plugin-syntax-import-assertions: ^7.24.7 => 7.24.7 @expo/vector-icons: ^14.0.2 => 14.0.2 @react-native-async-storage/async-storage: ^1.24.0 => 1.24.0 @react-native-community/datetimepicker: ^8.2.0 => 8.2.0 @react-native-community/netinfo: ^11.3.2 => 11.3.2 @react-native-picker/picker: ^2.7.7 => 2.7.7 @react-navigation/material-top-tabs: ^6.6.14 => 6.6.14 @react-navigation/native: ^6.1.18 => 6.1.18 @react-navigation/stack: ^6.4.1 => 6.4.1 @types/jest: ^29.5.12 => 29.5.12 @types/react: ~18.2.45 => 18.2.79 (18.3.3) @types/react-test-renderer: ^18.0.7 => 18.3.0 HelloWorld: 0.0.1 aws-amplify: ^6.5.0 => 6.5.0 aws-amplify-react-native: ^7.0.8 => 7.0.8 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/data: undefined () aws-amplify/data/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () aws-cdk: ^2.150.0 => 2.151.0 aws-cdk-lib: ^2.150.0 => 2.151.0 constructs: ^10.3.0 => 10.3.0 country-query: ^2.0.3 => 2.0.3 esbuild: ^0.23.0 => 0.23.0 expo: ^51.0.21 => 51.0.26 expo-constants: ~16.0.2 => 16.0.2 expo-font: ~12.0.9 => 12.0.9 expo-image-picker: ~15.0.7 => 15.0.7 expo-linear-gradient: ~13.0.2 => 13.0.2 expo-linking: ~6.3.1 => 6.3.1 expo-router: ~3.5.18 => 3.5.21 expo-splash-screen: ~0.27.5 => 0.27.5 expo-status-bar: ~1.12.1 => 1.12.1 expo-system-ui: ~3.0.7 => 3.0.7 expo-web-browser: ~13.0.3 => 13.0.3 jest: ^29.2.1 => 29.7.0 jest-expo: ~51.0.3 => 51.0.3 react: 18.2.0 => 18.2.0 react-dom: 18.2.0 => 18.2.0 react-iconly: ^2.2.10 => 2.2.10 react-native: 0.74.3 => 0.74.3 react-native-base64: ^0.2.1 => 0.2.1 react-native-country-picker-modal: ^2.0.0 => 2.0.0 react-native-elements: ^3.4.3 => 3.4.3 react-native-fs: ^2.20.0 => 2.20.0 react-native-gesture-handler: ~2.16.1 => 2.16.2 react-native-get-random-values: ^1.11.0 => 1.11.0 react-native-google-address-validation: ^1.2.7 => 1.2.7 react-native-iconly: ^1.0.12 => 1.0.12 react-native-linear-gradient: ^2.8.3 => 2.8.3 react-native-modal-datetime-picker: ^17.1.0 => 17.1.0 react-native-pager-view: 6.3.0 => 6.3.0 react-native-reanimated: ~3.10.1 => 3.10.1 react-native-safe-area-context: ^4.10.8 => 4.10.8 react-native-screens: 3.31.1 => 3.31.1 react-native-svg: ^15.4.0 => 15.5.0 (12.5.1) react-native-tab-view: ^3.5.2 => 3.5.2 react-native-tag-input: ^0.0.21 => 0.0.21 react-native-tags-input: ^1.0.10 => 1.0.10 react-native-url-polyfill: ^2.0.0 => 2.0.0 react-native-vector-icons: ^10.1.0 => 10.1.0 react-native-web: ~0.19.10 => 0.19.12 react-navigation-stack: ^2.10.4 => 2.10.4 react-phone-number-input: ^3.4.5 => 3.4.5 react-phone-number-input/commonjs: undefined () react-phone-number-input/core: undefined () react-phone-number-input/flags: undefined () react-phone-number-input/input-core: undefined () react-phone-number-input/input-max: undefined () react-phone-number-input/input-min: undefined () react-phone-number-input/input-mobile: undefined () react-phone-number-input/max: undefined () react-phone-number-input/min: undefined () react-phone-number-input/mobile: undefined () react-phone-number-input/react-hook-form: undefined () react-phone-number-input/react-hook-form-core: undefined () react-phone-number-input/react-hook-form-input: undefined () react-phone-number-input/react-hook-form-input-core: undefined () react-phone-number-input/react-native-input: undefined () react-phone-number-input/react-styleguidist: undefined () react-test-renderer: 18.2.0 => 18.2.0 tsx: ^4.16.3 => 4.17.0 typescript: ^5.5.4 => 5.5.4 (4.4.4, 4.9.5) npmGlobalPackages: @aws-amplify/cli: 12.12.4 @aws-amplify/ui-react-native: 2.2.3 aws-amplify: 6.4.3 eas-cli: 10.2.2 react-native-cli: 2.0.1 yarn: 1.22.22 ```

Describe the bug

When creating multiple users on my app (using cognito userpools), after a few created users (sometimes 1, sometimes 2 it's random), my app throws the following errors:

 LOG  [INFO] 27:04.571 Reachability - subscribing to reachability in React Native
 LOG  [INFO] 27:04.571 Reachability - Notifying reachability change true
 WARN  [WARN] 27:05.97 DataStore {"cause": {"data": {"syncConsultantProfiles": [Object]}, "errors": [[Object]]}, "errorType": "Unauthorized", "localModel": null, "message": undefined, "model": "ConsultantProfile", "operation": "syncConsultantProfiles", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
 WARN  [WARN] 27:05.111 DataStore - User is unauthorized to query syncConsultantProfiles with auth mode userPool. No data could be returned.
 WARN  [WARN] 27:05.497 DataStore {"cause": {"data": {"syncUserProfiles": [Object]}, "errors": [[Object]]}, "errorType": "Unauthorized", "localModel": null, "message": undefined, "model": "UserProfile", "operation": "syncUserProfiles", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
 WARN  [WARN] 27:05.511 DataStore - User is unauthorized to query syncUserProfiles with auth mode userPool. No data could be returned.

And then, i get the error no matter which account I use!!! The first or second or whatever

I've checked on the Cognito console, all accounts belong to the same group, which belongs to a authRole on which i have AdministratorAccess-Amplify and AWSAppSyncAdministrator. So maybe i'm mistaken, but i don't think the problem actually is with my roles / auth. Also, my app is able to Push newly created items, but when i refresh my local data, the app is not aware of the item's existance and it can't sync so it never knows the item exists serverside...

My AWS Console AppSync settings show main auth mode as Cognito, with the proper user group attached.

IMPORTANT TO NOTE, When I go to Console AppSync, then go to Requests, when I call syncUserProfiles or any sync by connecting to the problematic user, the request successfully goes through.

I have looked at the similar issues already, and did every single thing i saw in them, including: "createAPIKey":1 -> amplify push "createAPIKey":0 -> amplify push amplify rebuild api 'amplify update auth' -> 'create or update admin queries API' import using import { DataStore } from '@aws-amplify/datastore'; import using import {DataStore} from 'aws-amplify' (doesn't import properly) Removed node_modules, package_lock, yarn.lock, and run yarn install

I have ran amplify diagnose --send-report With this output: Project Identifier: 02a6e952317032d9500c24b89b51b4c8

Expected behavior

DataStore should be able to sync on every model.

Reproduction steps

  1. Setup Amplify-cli with auth(cognito userpools) and GraphQL api
  2. Edit the amplify/backend/api/YOURAPINAME/schema.graphql with the schema I gave
  3. Create an account in the app, then log in, then run a DataStore.save and or a DataStore.query to make sure the bug isn't active.
  4. Repeat step above multiple times, and restart the app inbetween each test (test multiple accounts!)
  5. The bug should eventually appear (personnally after 1-2-3 accounts it appears, it's random)

Code Snippet


import awsconfig from './../src/aws-exports';
import { Amplify } from 'aws-amplify';
import { Hub } from 'aws-amplify/utils';

Amplify.configure(awsconfig);

import { DataStore, Predicates } from '@aws-amplify/datastore';

export default function RootLayout() {
// I have tried DataStore.clear and DataStore.start already, nothing fixes it.
    const checkUser = async (createdProfile) => {
      try{
        const currUser = await getCurrentUser();

        const profiles = await DataStore.query(UserProfile, (profile) => profile.owner.eq(currUser.userId));
        console.log('profiles: ', profiles);
      }catch(e){
        console.log(e);
      }
    };

    useLayoutEffect(() => {
      async function fetchData() {
        await checkUser();
        SplashScreen.hideAsync();
      }
      fetchData();

      Hub.listen('auth', ({ payload }) => {
        switch (payload.event) {
          case 'signedIn':
            console.log('user have been signedIn successfully.');
            checkUser();
            break;
          case 'signedOut':
            console.log('user have been signedOut successfully.');
            checkUser();
            break;

        }
      });

    }, []);

      return (
        <View><Text>Hello world</Text></View>
    )
}
enum ProfileType {
  CONSULTANT
#... TRUNCATED BECAUSE USELESS HERE
}

type UserProfile @model @auth(rules: [{ allow: private, operations: [read] }, { allow: owner, ownerField: "owner" }]) {
  id: ID!
  owner: String @auth(rules: [{ allow: owner, operations: [read, delete] }])

  firstName: String!
  lastName: String!
  profilePicture: String
  birthdate: AWSDate!
  phoneNumber: String
  streetAddress: String
  city: String
  state: String
  postCode: String
  country: String
  profileType: ProfileType!
  consultantProfile: ConsultantProfile @belongsTo
}

type ConsultantProfile @model @auth(rules: [{ allow: private, operations: [read] }, { allow: owner, ownerField: "owner" }]) {
  id: ID!
  owner: ID @auth(rules: [{ allow: owner, operations: [read, delete] }])
  ownerUserProfile: UserProfile @hasOne(fields: ["owner"])
  firstName: String!
  lastName: String!
  tvaNumber: String
  streetAddress: String
  city: String
  state: String
  postCode: String
  country: String
  birthdate: AWSDate!
  bio: String
  tags: [String]
  pictures: [String]
  price: String
  jobTitle: String
  spokenLanguages: [String]
}

Log output

``` LOG [INFO] 27:04.571 Reachability - subscribing to reachability in React Native LOG [INFO] 27:04.571 Reachability - Notifying reachability change true WARN [WARN] 27:05.97 DataStore {"cause": {"data": {"syncConsultantProfiles": [Object]}, "errors": [[Object]]}, "errorType": "Unauthorized", "localModel": null, "message": undefined, "model": "ConsultantProfile", "operation": "syncConsultantProfiles", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null} WARN [WARN] 27:05.111 DataStore - User is unauthorized to query syncConsultantProfiles with auth mode userPool. No data could be returned. WARN [WARN] 27:05.497 DataStore {"cause": {"data": {"syncUserProfiles": [Object]}, "errors": [[Object]]}, "errorType": "Unauthorized", "localModel": null, "message": undefined, "model": "UserProfile", "operation": "syncUserProfiles", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null} WARN [WARN] 27:05.511 DataStore - User is unauthorized to query syncUserProfiles with auth mode userPool. No data could be returned. ```

aws-exports.js

// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "eu-north-1",
    "aws_appsync_graphqlEndpoint": "https://xxx.appsync-api.eu-north-1.amazonaws.com/graphql",
    "aws_appsync_region": "eu-north-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
    "aws_appsync_apiKey": "da2-24m3fgx24fbpjno7qif3yifkrm",
    "aws_cognito_identity_pool_id": "eu-north-1:xxx",
    "aws_cognito_region": "eu-north-1",
    "aws_user_pools_id": "eu-north-1_xxx",
    "aws_user_pools_web_client_id": "xxx",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL",
        "PHONE_NUMBER"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL",
        "FAMILY_NAME",
        "GIVEN_NAME",
        "PHONE_NUMBER"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_user_files_s3_bucket": "xxx-dev",
    "aws_user_files_s3_bucket_region": "eu-north-1"
};

export default awsmobile;

Manual configuration

No response

Additional configuration

{
    "UserPool": {
        "Id": "eu-north-XXXX",
        "Name": "XXXX_userpool_XXXX-dev",
        "Policies": {
            "PasswordPolicy": {
                "MinimumLength": 8,
                "RequireUppercase": false,
                "RequireLowercase": false,
                "RequireNumbers": false,
                "RequireSymbols": false,
                "TemporaryPasswordValidityDays": 7
            }
        },
        "DeletionProtection": "INACTIVE",
        "LambdaConfig": {
            "CustomMessage": "arn:aws:lambda:eu-north-1:XXXX:function:XXXX-dev",
            "PostConfirmation": "arn:aws:lambda:eu-north-1:XXXX:function:XXXX-dev"
        },
        "LastModifiedDate": "2024-08-11T18:00:45.620000+02:00",
        "CreationDate": "2024-08-04T22:19:45.777000+02:00",
        "SchemaAttributes": [
            {
                "Name": "profile",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "address",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "birthdate",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "10",
                    "MaxLength": "10"
                }
            },
            {
                "Name": "gender",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "preferred_username",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "updated_at",
                "AttributeDataType": "Number",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "NumberAttributeConstraints": {
                    "MinValue": "0"
                }
            },
            {
                "Name": "website",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "picture",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "identities",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {}
            },
            {
                "Name": "sub",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": false,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "1",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "phone_number",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "phone_number_verified",
                "AttributeDataType": "Boolean",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false
            },
            {
                "Name": "zoneinfo",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "locale",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "email",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "email_verified",
                "AttributeDataType": "Boolean",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false
            },
            {
                "Name": "given_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "family_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "middle_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "nickname",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            }
        ],
        "AutoVerifiedAttributes": [
            "email"
        ],
        "UsernameAttributes": [
            "email",
            "phone_number"
        ],
        "SmsVerificationMessage": "Your verification code is {####}",
        "EmailVerificationMessage": "Hey, welcome to consultU!\n\nYour verification code is {####}\n\nPlease, confirm your account to get access to the app quickly!",
        "EmailVerificationSubject": "Your consultU verification code",
        "VerificationMessageTemplate": {
            "SmsMessage": "Your verification code is {####}",
            "EmailMessage": "Hey, welcome to consultU!\n\nYour verification code is {####}\n\nPlease, confirm your account to get access to the app quickly!",
            "EmailSubject": "Your consultU verification code",
            "DefaultEmailOption": "CONFIRM_WITH_CODE"
        },
        "SmsAuthenticationMessage": "Your authentication code is {####}",
        "UserAttributeUpdateSettings": {
            "AttributesRequireVerificationBeforeUpdate": [
                "email"
            ]
        },
        "MfaConfiguration": "OFF",
        "EstimatedNumberOfUsers": 3,
        "EmailConfiguration": {
            "EmailSendingAccount": "COGNITO_DEFAULT"
        },
        "SmsConfiguration": {
            "SnsCallerArn": "arn:aws:iam::XXXX:role/XXXX-dev",
            "ExternalId": "consuldd70f094_role_external_id",
            "SnsRegion": "eu-north-1"
        },
        "UserPoolTags": {},
        "SmsConfigurationFailure": "SNSSandbox",
        "AdminCreateUserConfig": {
            "AllowAdminCreateUserOnly": false,
            "UnusedAccountValidityDays": 7
        },
        "UsernameConfiguration": {
            "CaseSensitive": false
        },
        "Arn": "arn:aws:cognito-idp:eu-north-1:XXXX:userpool/eu-north-1_XXXX",
        "AccountRecoverySetting": {
            "RecoveryMechanisms": [
                {
                    "Priority": 1,
                    "Name": "verified_email"
                },
                {
                    "Priority": 2,
                    "Name": "verified_phone_number"
                }
            ]
        }
    }
}

Mobile Device

Pixel 8

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

Gaztoof commented 3 months ago

Upon further investigation, it turns out this bug only happens when I have multiple instances of UserProfile in my DynamoDB, so when I have only one UserProfile, no problem! Everything runs flawless! But as soon as I have more than one, the error starts appearing on all users. But the moment I remove the second UserProfile from the database, the error is gone... Wtf ?

HuiSF commented 3 months ago

Hi @Gaztoof I'm not an expert on datastore in Amplify JS, but IIRC, the field auth (attached to the owner field of your models) is not working well within DataStore. This owner field is only accessible to the actually owner, but when the sync queries are applicable to all signed-in users (this seems aligning to the observation in your last comment). Could you try the following see whether it eliminates the unauthorized error.

Gaztoof commented 3 months ago

Hi @Gaztoof I'm not an expert on datastore in Amplify JS, but IIRC, the field auth (attached to the owner field of your models) is not working well within DataStore. This owner field is only accessible to the actually owner, but when the sync queries are applicable to all signed-in users (this seems aligning to the observation in your last comment). Could you try the following see whether it eliminates the unauthorized error.

  • Update the auth rule of the owner field to allow read for all signed-in user
  • And if that doesn't work can you try remove the auth rule attached to the owner field completely

Thanks a lot! Totally removing every field's @auth fixed the problem! Which unfortunately now leads to security concerns but i'll eventually figure that out...