Amplify.DataStore.query 正在返回所有用户创建的数据,而不是仅返回所有者创建的数据
Amplify.DataStore.query is returning data created by all users, instead of owner only
当我 运行 查询时,我从所有用户(所有者)获取数据,而不仅仅是当前登录的所有者。我想如果我有这个:[创建、更新、删除、读取] 只有所有者才能读取他们的数据?这里发生了什么?我错过了什么?
我使用的是同一台设备(模拟器),但我使用不同的帐户登录和退出。
Amplify.DataStore.query(Todo.class,
all -> {
while (all.hasNext()) {
Todo todo1 = all.next();
Log.i("tag", "Title: " + todo1.getName());
}
},
failure -> Log.e("tag", "Query failed.", failure)
);
type Todo
@model
@auth(
rules: [
{
allow: owner,
ownerField: "owner",
operations: [create, update, delete, read]
}
]
) {
id: ID!
owner: String
name: String!
}
我想我在这里找到了解决方案:
https://docs.amplify.aws/lib/datastore/sync/q/platform/android#update-and-delete-with-predicate
每次在同一设备上切换用户时,都必须调用 Amplify.DataStore.clear()
Note: In case multiple users share the same device and your schema
defines user-specific data, make sure you call
Amplify.DataStore.clear() when switching users. Visit Auth events for
all authentication related events.
当我 运行 查询时,我从所有用户(所有者)获取数据,而不仅仅是当前登录的所有者。我想如果我有这个:[创建、更新、删除、读取] 只有所有者才能读取他们的数据?这里发生了什么?我错过了什么?
我使用的是同一台设备(模拟器),但我使用不同的帐户登录和退出。
Amplify.DataStore.query(Todo.class,
all -> {
while (all.hasNext()) {
Todo todo1 = all.next();
Log.i("tag", "Title: " + todo1.getName());
}
},
failure -> Log.e("tag", "Query failed.", failure)
);
type Todo
@model
@auth(
rules: [
{
allow: owner,
ownerField: "owner",
operations: [create, update, delete, read]
}
]
) {
id: ID!
owner: String
name: String!
}
我想我在这里找到了解决方案:
https://docs.amplify.aws/lib/datastore/sync/q/platform/android#update-and-delete-with-predicate
每次在同一设备上切换用户时,都必须调用 Amplify.DataStore.clear()
Note: In case multiple users share the same device and your schema defines user-specific data, make sure you call Amplify.DataStore.clear() when switching users. Visit Auth events for all authentication related events.