-
Notifications
You must be signed in to change notification settings - Fork 199
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
App Sync throwing "Not Authorized" for some fields #3159
Comments
Here's my amplifyconfiguration.json Details
|
Thanks for opening this issue. The team will investigate and get back to you as soon as we have more information. |
Was there any updates on this issue? |
After further investigation, I noticed the web project is performing a query with fewer fields than the iOS does: Query from web project
Query from iOS project
But the same query that's defined at Query from lambda folder
Testing both queries on AppSync console with an authenticated user, I managed to get the data using the web query, while the iOS query returned unauthorized errors as the DataStore sync errors I sent before. So I believe that's why I don't get the iOS errors on web, but the question I raise is: There's a way to modify the query structure on iOS? Or maybe modify it on backend? |
Hey, are there any updates on your investigation, and what's the average time it usually takes to receive updates? |
Hi @peaugust, thanks for the deatils on the queries. I can see that you're also using Amplify Library version 2.15.2 which includes changes from 2.4 that reduces the iOS queries to what you saw in the other platforms. This was only possible because the model types with lazy loading capabilities allow data to be decoded successfully with the selection set reduction. To generate the new model types, please enable the feature flag For more information, please see https://docs.amplify.aws/cli/migration/lazy-load-custom-selection-set/#cross-platform-app-development-with-datastore-swift and feel free to reach out with any more questions |
Hi @lawmicha, I've added the feature flag to DataStore Logs
|
I accidentally closed this issue while I was formatting these comment. Sorry about that. Connection+Schema diff// swiftlint:disable all
import Amplify
import Foundation
extension Connection {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case owner
case chatId
case userId
case memberId
case user
case member
case onlinePresence
case isSender
case isReceiver
case isAccepted
case isDeclined
case isBlocked
case isMuted
case isPinned
case acceptedAt
case declinedAt
case blockedAt
case mutedAt
case pinnedAt
case createdAt
case updatedAt
}
public static let keys = CodingKeys.self
// MARK: - ModelSchema
public static let schema = defineSchema { model in
let connection = Connection.keys
model.authRules = [
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read])
]
- model.pluralName = "Connections"
+ model.listPluralName = "Connections"
+ model.syncPluralName = "Connections"
model.attributes(
.index(fields: ["chatId", "createdAt"], name: "listConnectionByChatId"),
.index(fields: ["userId", "createdAt"], name: "listConnectionByUserId"),
.index(fields: ["memberId", "createdAt"], name: "listConnectionByMemberId")
)
model.fields(
.id(),
.field(connection.owner, is: .optional, ofType: .string),
.field(connection.chatId, is: .optional, ofType: .string),
.field(connection.userId, is: .optional, ofType: .string),
.field(connection.memberId, is: .optional, ofType: .string),
.hasOne(connection.user, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "userId"),
.hasOne(connection.member, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "memberId"),
.hasOne(connection.onlinePresence, is: .optional, ofType: OnlinePresence.self, associatedWith: OnlinePresence.keys.id, targetName: "memberId"),
.field(connection.isSender, is: .optional, ofType: .bool),
.field(connection.isReceiver, is: .optional, ofType: .bool),
.field(connection.isAccepted, is: .optional, ofType: .bool),
.field(connection.isDeclined, is: .optional, ofType: .bool),
.field(connection.isBlocked, is: .optional, ofType: .bool),
.field(connection.isMuted, is: .optional, ofType: .bool),
.field(connection.isPinned, is: .optional, ofType: .bool),
.field(connection.acceptedAt, is: .optional, ofType: .dateTime),
.field(connection.declinedAt, is: .optional, ofType: .dateTime),
.field(connection.blockedAt, is: .optional, ofType: .dateTime),
.field(connection.mutedAt, is: .optional, ofType: .dateTime),
.field(connection.pinnedAt, is: .optional, ofType: .dateTime),
.field(connection.createdAt, is: .optional, ofType: .dateTime),
.field(connection.updatedAt, is: .optional, ofType: .dateTime)
)
}
public class Path: ModelPath<Connection> { }
public static var rootPath: PropertyContainerPath? { Path() }
}
+extension ModelPath where ModelType == Connection {
+ public var id: FieldPath<String> {
+ string("id")
+ }
+ public var owner: FieldPath<String> {
+ string("owner")
+ }
+ public var chatId: FieldPath<String> {
+ string("chatId")
+ }
+ public var userId: FieldPath<String> {
+ string("userId")
+ }
+ public var memberId: FieldPath<String> {
+ string("memberId")
+ }
+ public var user: ModelPath<User> {
+ User.Path(name: "user", parent: self)
+ }
+ public var member: ModelPath<User> {
+ User.Path(name: "member", parent: self)
+ }
+ public var onlinePresence: ModelPath<OnlinePresence> {
+ OnlinePresence.Path(name: "onlinePresence", parent: self)
+ }
+ public var isSender: FieldPath<Bool> {
+ bool("isSender")
+ }
+ public var isReceiver: FieldPath<Bool> {
+ bool("isReceiver")
+ }
+ public var isAccepted: FieldPath<Bool> {
+ bool("isAccepted")
+ }
+ public var isDeclined: FieldPath<Bool> {
+ bool("isDeclined")
+ }
+ public var isBlocked: FieldPath<Bool> {
+ bool("isBlocked")
+ }
+ public var isMuted: FieldPath<Bool> {
+ bool("isMuted")
+ }
+ public var isPinned: FieldPath<Bool> {
+ bool("isPinned")
+ }
+ public var acceptedAt: FieldPath<Temporal.DateTime> {
+ datetime("acceptedAt")
+ }
+ public var declinedAt: FieldPath<Temporal.DateTime> {
+ datetime("declinedAt")
+ }
+ public var blockedAt: FieldPath<Temporal.DateTime> {
+ datetime("blockedAt")
+ }
+ public var mutedAt: FieldPath<Temporal.DateTime> {
+ datetime("mutedAt")
+ }
+ public var pinnedAt: FieldPath<Temporal.DateTime> {
+ datetime("pinnedAt")
+ }
+ public var createdAt: FieldPath<Temporal.DateTime> {
+ datetime("createdAt")
+ }
+ public var updatedAt: FieldPath<Temporal.DateTime> {
+ datetime("updatedAt")
+ }
+} Connection diff// swiftlint:disable all
import Amplify
import Foundation
public struct Connection: Model {
public let id: String
public var owner: String?
public var chatId: String?
public var userId: String?
public var memberId: String?
+ internal var _user: LazyReference<User>
- public var user: User?
+ public var user: User? {
+ get async throws {
+ try await _user.get()
+ }
+ }
+ internal var _member: LazyReference<User>
- public var member: User?
+ public var member: User? {
+ get async throws {
+ try await _member.get()
+ }
+ }
+ internal var _onlinePresence: LazyReference<OnlinePresence>
- public var onlinePresence: OnlinePresence?
+ public var onlinePresence: OnlinePresence? {
+ get async throws {
+ try await _onlinePresence.get()
+ }
+ }
public var isSender: Bool?
public var isReceiver: Bool?
public var isAccepted: Bool?
public var isDeclined: Bool?
public var isBlocked: Bool?
public var isMuted: Bool?
public var isPinned: Bool?
public var acceptedAt: Temporal.DateTime?
public var declinedAt: Temporal.DateTime?
public var blockedAt: Temporal.DateTime?
public var mutedAt: Temporal.DateTime?
public var pinnedAt: Temporal.DateTime?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
public init(id: String = UUID().uuidString,
owner: String? = nil,
chatId: String? = nil,
userId: String? = nil,
memberId: String? = nil,
user: User? = nil,
member: User? = nil,
onlinePresence: OnlinePresence? = nil,
isSender: Bool? = nil,
isReceiver: Bool? = nil,
isAccepted: Bool? = nil,
isDeclined: Bool? = nil,
isBlocked: Bool? = nil,
isMuted: Bool? = nil,
isPinned: Bool? = nil,
acceptedAt: Temporal.DateTime? = nil,
declinedAt: Temporal.DateTime? = nil,
blockedAt: Temporal.DateTime? = nil,
mutedAt: Temporal.DateTime? = nil,
pinnedAt: Temporal.DateTime? = nil,
createdAt: Temporal.DateTime? = nil,
updatedAt: Temporal.DateTime? = nil) {
self.id = id
self.owner = owner
self.chatId = chatId
self.userId = userId
self.memberId = memberId
- self.user = user
- self.member = member
- self.onlinePresence = onlinePresence
+ self._user = LazyReference(user)
+ self._member = LazyReference(member)
+ self._onlinePresence = LazyReference(onlinePresence)
self.isSender = isSender
self.isReceiver = isReceiver
self.isAccepted = isAccepted
self.isDeclined = isDeclined
self.isBlocked = isBlocked
self.isMuted = isMuted
self.isPinned = isPinned
self.acceptedAt = acceptedAt
self.declinedAt = declinedAt
self.blockedAt = blockedAt
self.mutedAt = mutedAt
self.pinnedAt = pinnedAt
self.createdAt = createdAt
self.updatedAt = updatedAt
}
+ public mutating func setUser(_ user: User? = nil) {
+ self._user = LazyReference(user)
+ }
+ public mutating func setMember(_ member: User? = nil) {
+ self._member = LazyReference(member)
+ }
+ public mutating func setOnlinePresence(_ onlinePresence: OnlinePresence? = nil) {
+ self._onlinePresence = LazyReference(onlinePresence)
+ }
+ public init(from decoder: Decoder) throws {
+ let values = try decoder.container(keyedBy: CodingKeys.self)
+ id = try values.decode(String.self, forKey: .id)
+ owner = try? values.decode(String?.self, forKey: .owner)
+ chatId = try? values.decode(String?.self, forKey: .chatId)
+ userId = try? values.decode(String?.self, forKey: .userId)
+ memberId = try? values.decode(String?.self, forKey: .memberId)
+ _user = try values.decodeIfPresent(LazyReference<User>.self, forKey: .user) ?? LazyReference(identifiers: nil)
+ _member = try values.decodeIfPresent(LazyReference<User>.self, forKey: .member) ?? LazyReference(identifiers: nil)
+ _onlinePresence = try values.decodeIfPresent(LazyReference<OnlinePresence>.self, forKey: .onlinePresence) ?? LazyReference(identifiers: nil)
+ isSender = try? values.decode(Bool?.self, forKey: .isSender)
+ isReceiver = try? values.decode(Bool?.self, forKey: .isReceiver)
+ isAccepted = try? values.decode(Bool?.self, forKey: .isAccepted)
+ isDeclined = try? values.decode(Bool?.self, forKey: .isDeclined)
+ isBlocked = try? values.decode(Bool?.self, forKey: .isBlocked)
+ isMuted = try? values.decode(Bool?.self, forKey: .isMuted)
+ isPinned = try? values.decode(Bool?.self, forKey: .isPinned)
+ acceptedAt = try? values.decode(Temporal.DateTime?.self, forKey: .acceptedAt)
+ declinedAt = try? values.decode(Temporal.DateTime?.self, forKey: .declinedAt)
+ blockedAt = try? values.decode(Temporal.DateTime?.self, forKey: .blockedAt)
+ mutedAt = try? values.decode(Temporal.DateTime?.self, forKey: .mutedAt)
+ pinnedAt = try? values.decode(Temporal.DateTime?.self, forKey: .pinnedAt)
+ createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt)
+ updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt)
+ }
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.container(keyedBy: CodingKeys.self)
+ try container.encode(id, forKey: .id)
+ try container.encode(owner, forKey: .owner)
+ try container.encode(chatId, forKey: .chatId)
+ try container.encode(userId, forKey: .userId)
+ try container.encode(memberId, forKey: .memberId)
+ try container.encode(_user, forKey: .user)
+ try container.encode(_member, forKey: .member)
+ try container.encode(_onlinePresence, forKey: .onlinePresence)
+ try container.encode(isSender, forKey: .isSender)
+ try container.encode(isReceiver, forKey: .isReceiver)
+ try container.encode(isAccepted, forKey: .isAccepted)
+ try container.encode(isDeclined, forKey: .isDeclined)
+ try container.encode(isBlocked, forKey: .isBlocked)
+ try container.encode(isMuted, forKey: .isMuted)
+ try container.encode(isPinned, forKey: .isPinned)
+ try container.encode(acceptedAt, forKey: .acceptedAt)
+ try container.encode(declinedAt, forKey: .declinedAt)
+ try container.encode(blockedAt, forKey: .blockedAt)
+ try container.encode(mutedAt, forKey: .mutedAt)
+ try container.encode(pinnedAt, forKey: .pinnedAt)
+ try container.encode(createdAt, forKey: .createdAt)
+ try container.encode(updatedAt, forKey: .updatedAt)
+ }
+} |
Hey folks, any updates on this issue? |
@lawmicha, I successfully managed to complete datastore sync, although I had to remove by hand the fields that were returning as unauthorized from the models generated by the codegen. I realize that I'll need to execute separate queries to retrieve the items I removed, but for the time being, I'm unblocked. However, I would greatly appreciate it if we find a permanent solution to this issue. |
Hey @peaugust, thanks for following up, we'll need to investigate this further. I can see the JS query for syncConnection contains
I think because it's including the |
Do you have an updated schema we can use for reproduction? Which fields did you remove by hand? |
Hi @lawmicha, here are the fields I removed from Connection and Participants. After that I managed to see DataStore completing the sync process, and I was also able to see logs on my terminal my app was receiving changes that were happening on real time. Connection+Schema diff// swiftlint:disable all
import Amplify
import Foundation
extension Connection {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case owner
case chatId
case userId
case memberId
case user
- case member
case onlinePresence
case isSender
case isReceiver
case isAccepted
case isDeclined
case isBlocked
case isMuted
case isPinned
case acceptedAt
case declinedAt
case blockedAt
case mutedAt
case pinnedAt
case createdAt
case updatedAt
}
public static let keys = CodingKeys.self
// MARK: - ModelSchema
public static let schema = defineSchema { model in
let connection = Connection.keys
model.authRules = [
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read])
]
model.listPluralName = "Connections"
model.syncPluralName = "Connections"
model.attributes(
.index(fields: ["chatId", "createdAt"], name: "listConnectionByChatId"),
.index(fields: ["userId", "createdAt"], name: "listConnectionByUserId"),
.index(fields: ["memberId", "createdAt"], name: "listConnectionByMemberId")
)
model.fields(
.id(),
.field(connection.owner, is: .optional, ofType: .string),
.field(connection.chatId, is: .optional, ofType: .string),
.field(connection.userId, is: .optional, ofType: .string),
.field(connection.memberId, is: .optional, ofType: .string),
.hasOne(connection.user, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "userId"),
- .hasOne(connection.member, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "memberId"),
.hasOne(connection.onlinePresence, is: .optional, ofType: OnlinePresence.self, associatedWith: OnlinePresence.keys.id, targetName: "memberId"),
.field(connection.isSender, is: .optional, ofType: .bool),
.field(connection.isReceiver, is: .optional, ofType: .bool),
.field(connection.isAccepted, is: .optional, ofType: .bool),
.field(connection.isDeclined, is: .optional, ofType: .bool),
.field(connection.isBlocked, is: .optional, ofType: .bool),
.field(connection.isMuted, is: .optional, ofType: .bool),
.field(connection.isPinned, is: .optional, ofType: .bool),
.field(connection.acceptedAt, is: .optional, ofType: .dateTime),
.field(connection.declinedAt, is: .optional, ofType: .dateTime),
.field(connection.blockedAt, is: .optional, ofType: .dateTime),
.field(connection.mutedAt, is: .optional, ofType: .dateTime),
.field(connection.pinnedAt, is: .optional, ofType: .dateTime),
.field(connection.createdAt, is: .optional, ofType: .dateTime),
.field(connection.updatedAt, is: .optional, ofType: .dateTime)
)
}
public class Path: ModelPath<Connection> { }
public static var rootPath: PropertyContainerPath? { Path() }
}
extension ModelPath where ModelType == Connection {
public var id: FieldPath<String> {
string("id")
}
public var owner: FieldPath<String> {
string("owner")
}
public var chatId: FieldPath<String> {
string("chatId")
}
public var userId: FieldPath<String> {
string("userId")
}
public var memberId: FieldPath<String> {
string("memberId")
}
public var user: ModelPath<User> {
User.Path(name: "user", parent: self)
}
- public var member: ModelPath<User> {
- User.Path(name: "member", parent: self)
- }
public var onlinePresence: ModelPath<OnlinePresence> {
OnlinePresence.Path(name: "onlinePresence", parent: self)
}
public var isSender: FieldPath<Bool> {
bool("isSender")
}
public var isReceiver: FieldPath<Bool> {
bool("isReceiver")
}
public var isAccepted: FieldPath<Bool> {
bool("isAccepted")
}
public var isDeclined: FieldPath<Bool> {
bool("isDeclined")
}
public var isBlocked: FieldPath<Bool> {
bool("isBlocked")
}
public var isMuted: FieldPath<Bool> {
bool("isMuted")
}
public var isPinned: FieldPath<Bool> {
bool("isPinned")
}
public var acceptedAt: FieldPath<Temporal.DateTime> {
datetime("acceptedAt")
}
public var declinedAt: FieldPath<Temporal.DateTime> {
datetime("declinedAt")
}
public var blockedAt: FieldPath<Temporal.DateTime> {
datetime("blockedAt")
}
public var mutedAt: FieldPath<Temporal.DateTime> {
datetime("mutedAt")
}
public var pinnedAt: FieldPath<Temporal.DateTime> {
datetime("pinnedAt")
}
public var createdAt: FieldPath<Temporal.DateTime> {
datetime("createdAt")
}
public var updatedAt: FieldPath<Temporal.DateTime> {
datetime("updatedAt")
} Connection diff// swiftlint:disable all
import Amplify
import Foundation
public struct Connection: Model {
public let id: String
public var owner: String?
public var chatId: String?
public var userId: String?
public var memberId: String?
internal var _user: LazyReference<User>
public var user: User? {
get async throws {
try await _user.get()
}
}
- internal var _member: LazyReference<User>
- public var member: User? {
- get async throws {
- try await _member.get()
- }
- }
internal var _onlinePresence: LazyReference<OnlinePresence>
public var onlinePresence: OnlinePresence? {
get async throws {
try await _onlinePresence.get()
}
}
public var isSender: Bool?
public var isReceiver: Bool?
public var isAccepted: Bool?
public var isDeclined: Bool?
public var isBlocked: Bool?
public var isMuted: Bool?
public var isPinned: Bool?
public var acceptedAt: Temporal.DateTime?
public var declinedAt: Temporal.DateTime?
public var blockedAt: Temporal.DateTime?
public var mutedAt: Temporal.DateTime?
public var pinnedAt: Temporal.DateTime?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
public init(id: String = UUID().uuidString,
owner: String? = nil,
chatId: String? = nil,
userId: String? = nil,
memberId: String? = nil,
user: User? = nil,
- member: User? = nil,
onlinePresence: OnlinePresence? = nil,
isSender: Bool? = nil,
isReceiver: Bool? = nil,
isAccepted: Bool? = nil,
isDeclined: Bool? = nil,
isBlocked: Bool? = nil,
isMuted: Bool? = nil,
isPinned: Bool? = nil,
acceptedAt: Temporal.DateTime? = nil,
declinedAt: Temporal.DateTime? = nil,
blockedAt: Temporal.DateTime? = nil,
mutedAt: Temporal.DateTime? = nil,
pinnedAt: Temporal.DateTime? = nil,
createdAt: Temporal.DateTime? = nil,
updatedAt: Temporal.DateTime? = nil) {
self.id = id
self.owner = owner
self.chatId = chatId
self.userId = userId
self.memberId = memberId
self._user = LazyReference(user)
- self._member = LazyReference(member)
self._onlinePresence = LazyReference(onlinePresence)
self.isSender = isSender
self.isReceiver = isReceiver
self.isAccepted = isAccepted
self.isDeclined = isDeclined
self.isBlocked = isBlocked
self.isMuted = isMuted
self.isPinned = isPinned
self.acceptedAt = acceptedAt
self.declinedAt = declinedAt
self.blockedAt = blockedAt
self.mutedAt = mutedAt
self.pinnedAt = pinnedAt
self.createdAt = createdAt
self.updatedAt = updatedAt
}
public mutating func setUser(_ user: User? = nil) {
self._user = LazyReference(user)
}
- public mutating func setMember(_ member: User? = nil) {
- self._member = LazyReference(member)
- }
public mutating func setOnlinePresence(_ onlinePresence: OnlinePresence? = nil) {
self._onlinePresence = LazyReference(onlinePresence)
}
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
id = try values.decode(String.self, forKey: .id)
owner = try? values.decode(String?.self, forKey: .owner)
chatId = try? values.decode(String?.self, forKey: .chatId)
userId = try? values.decode(String?.self, forKey: .userId)
memberId = try? values.decode(String?.self, forKey: .memberId)
_user = try values.decodeIfPresent(LazyReference<User>.self, forKey: .user) ?? LazyReference(identifiers: nil)
- _member = try values.decodeIfPresent(LazyReference<User>.self, forKey: .member) ?? LazyReference(identifiers: nil)
_onlinePresence = try values.decodeIfPresent(LazyReference<OnlinePresence>.self, forKey: .onlinePresence) ?? LazyReference(identifiers: nil)
isSender = try? values.decode(Bool?.self, forKey: .isSender)
isReceiver = try? values.decode(Bool?.self, forKey: .isReceiver)
isAccepted = try? values.decode(Bool?.self, forKey: .isAccepted)
isDeclined = try? values.decode(Bool?.self, forKey: .isDeclined)
isBlocked = try? values.decode(Bool?.self, forKey: .isBlocked)
isMuted = try? values.decode(Bool?.self, forKey: .isMuted)
isPinned = try? values.decode(Bool?.self, forKey: .isPinned)
acceptedAt = try? values.decode(Temporal.DateTime?.self, forKey: .acceptedAt)
declinedAt = try? values.decode(Temporal.DateTime?.self, forKey: .declinedAt)
blockedAt = try? values.decode(Temporal.DateTime?.self, forKey: .blockedAt)
mutedAt = try? values.decode(Temporal.DateTime?.self, forKey: .mutedAt)
pinnedAt = try? values.decode(Temporal.DateTime?.self, forKey: .pinnedAt)
createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt)
updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(owner, forKey: .owner)
try container.encode(chatId, forKey: .chatId)
try container.encode(userId, forKey: .userId)
try container.encode(memberId, forKey: .memberId)
try container.encode(_user, forKey: .user)
- try container.encode(_member, forKey: .member)
try container.encode(_onlinePresence, forKey: .onlinePresence)
try container.encode(isSender, forKey: .isSender)
try container.encode(isReceiver, forKey: .isReceiver)
try container.encode(isAccepted, forKey: .isAccepted)
try container.encode(isDeclined, forKey: .isDeclined)
try container.encode(isBlocked, forKey: .isBlocked)
try container.encode(isMuted, forKey: .isMuted)
try container.encode(isPinned, forKey: .isPinned)
try container.encode(acceptedAt, forKey: .acceptedAt)
try container.encode(declinedAt, forKey: .declinedAt)
try container.encode(blockedAt, forKey: .blockedAt)
try container.encode(mutedAt, forKey: .mutedAt)
try container.encode(pinnedAt, forKey: .pinnedAt)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(updatedAt, forKey: .updatedAt)
}
} Participant+Schema diff// swiftlint:disable all
import Amplify
import Foundation
extension Participant {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case owner
- case room
case user
case roomId
case userId
case teamId
case onlinePresence
case role
case roomKey
case searchTerm
case isAccepted
case isDeclined
case isBlocked
case createdAt
case updatedAt
}
public static let keys = CodingKeys.self
// MARK: - ModelSchema
public static let schema = defineSchema { model in
let participant = Participant.keys
model.authRules = [
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.read])
]
model.listPluralName = "Participants"
model.syncPluralName = "Participants"
model.attributes(
.index(fields: ["roomId", "createdAt"], name: "listParticipantByRoomId"),
.index(fields: ["userId", "createdAt"], name: "listParticipantByUserId"),
.index(fields: ["teamId", "createdAt"], name: "listParticipantByTeamId")
)
model.fields(
.id(),
.field(participant.owner, is: .optional, ofType: .string),
- .hasOne(participant.room, is: .optional, ofType: Room.self, associatedWith: Room.keys.id, targetName: "roomId"),
.hasOne(participant.user, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "userId"),
.field(participant.roomId, is: .optional, ofType: .string),
.field(participant.userId, is: .optional, ofType: .string),
.field(participant.teamId, is: .optional, ofType: .string),
.hasOne(participant.onlinePresence, is: .optional, ofType: OnlinePresence.self, associatedWith: OnlinePresence.keys.id, targetName: "userId"),
.field(participant.role, is: .optional, ofType: .enum(type: Role.self)),
.field(participant.roomKey, is: .optional, ofType: .string),
.field(participant.searchTerm, is: .optional, ofType: .string),
.field(participant.isAccepted, is: .optional, ofType: .bool),
.field(participant.isDeclined, is: .optional, ofType: .bool),
.field(participant.isBlocked, is: .optional, ofType: .bool),
.field(participant.createdAt, is: .optional, ofType: .dateTime),
.field(participant.updatedAt, is: .optional, ofType: .dateTime)
)
}
public class Path: ModelPath<Participant> { }
public static var rootPath: PropertyContainerPath? { Path() }
}
extension ModelPath where ModelType == Participant {
public var id: FieldPath<String> {
string("id")
}
public var owner: FieldPath<String> {
string("owner")
}
- public var room: ModelPath<Room> {
- Room.Path(name: "room", parent: self)
- }
public var user: ModelPath<User> {
User.Path(name: "user", parent: self)
}
public var roomId: FieldPath<String> {
string("roomId")
}
public var userId: FieldPath<String> {
string("userId")
}
public var teamId: FieldPath<String> {
string("teamId")
}
public var onlinePresence: ModelPath<OnlinePresence> {
OnlinePresence.Path(name: "onlinePresence", parent: self)
}
public var roomKey: FieldPath<String> {
string("roomKey")
}
public var searchTerm: FieldPath<String> {
string("searchTerm")
}
public var isAccepted: FieldPath<Bool> {
bool("isAccepted")
}
public var isDeclined: FieldPath<Bool> {
bool("isDeclined")
}
public var isBlocked: FieldPath<Bool> {
bool("isBlocked")
}
public var createdAt: FieldPath<Temporal.DateTime> {
datetime("createdAt")
}
public var updatedAt: FieldPath<Temporal.DateTime> {
datetime("updatedAt")
}
} Participant diff// swiftlint:disable all
import Amplify
import Foundation
public struct Participant: Model {
public let id: String
public var owner: String?
- internal var _room: LazyReference<Room>
- public var room: Room? {
- get async throws {
- try await _room.get()
- }
- }
internal var _user: LazyReference<User>
public var user: User? {
get async throws {
try await _user.get()
}
}
public var roomId: String?
public var userId: String?
public var teamId: String?
internal var _onlinePresence: LazyReference<OnlinePresence>
public var onlinePresence: OnlinePresence? {
get async throws {
try await _onlinePresence.get()
}
}
public var role: Role?
public var roomKey: String?
public var searchTerm: String?
public var isAccepted: Bool?
public var isDeclined: Bool?
public var isBlocked: Bool?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
public init(id: String = UUID().uuidString,
owner: String? = nil,
room: Room? = nil,
user: User? = nil,
roomId: String? = nil,
userId: String? = nil,
teamId: String? = nil,
onlinePresence: OnlinePresence? = nil,
role: Role? = nil,
roomKey: String? = nil,
searchTerm: String? = nil,
isAccepted: Bool? = nil,
isDeclined: Bool? = nil,
isBlocked: Bool? = nil,
createdAt: Temporal.DateTime? = nil,
updatedAt: Temporal.DateTime? = nil) {
self.id = id
self.owner = owner
- self._room = LazyReference(room)
self._user = LazyReference(user)
self.roomId = roomId
self.userId = userId
self.teamId = teamId
self._onlinePresence = LazyReference(onlinePresence)
self.role = role
self.roomKey = roomKey
self.searchTerm = searchTerm
self.isAccepted = isAccepted
self.isDeclined = isDeclined
self.isBlocked = isBlocked
self.createdAt = createdAt
self.updatedAt = updatedAt
}
- public mutating func setRoom(_ room: Room? = nil) {
- self._room = LazyReference(room)
- }
public mutating func setUser(_ user: User? = nil) {
self._user = LazyReference(user)
}
public mutating func setOnlinePresence(_ onlinePresence: OnlinePresence? = nil) {
self._onlinePresence = LazyReference(onlinePresence)
}
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
id = try values.decode(String.self, forKey: .id)
owner = try? values.decode(String?.self, forKey: .owner)
- _room = try values.decodeIfPresent(LazyReference<Room>.self, forKey: .room) ?? LazyReference(identifiers: nil)
_user = try values.decodeIfPresent(LazyReference<User>.self, forKey: .user) ?? LazyReference(identifiers: nil)
roomId = try? values.decode(String?.self, forKey: .roomId)
userId = try? values.decode(String?.self, forKey: .userId)
teamId = try? values.decode(String?.self, forKey: .teamId)
_onlinePresence = try values.decodeIfPresent(LazyReference<OnlinePresence>.self, forKey: .onlinePresence) ?? LazyReference(identifiers: nil)
role = try? values.decode(Role?.self, forKey: .role)
roomKey = try? values.decode(String?.self, forKey: .roomKey)
searchTerm = try? values.decode(String?.self, forKey: .searchTerm)
isAccepted = try? values.decode(Bool?.self, forKey: .isAccepted)
isDeclined = try? values.decode(Bool?.self, forKey: .isDeclined)
isBlocked = try? values.decode(Bool?.self, forKey: .isBlocked)
createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt)
updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(owner, forKey: .owner)
- try container.encode(_room, forKey: .room)
try container.encode(_user, forKey: .user)
try container.encode(roomId, forKey: .roomId)
try container.encode(userId, forKey: .userId)
try container.encode(teamId, forKey: .teamId)
try container.encode(_onlinePresence, forKey: .onlinePresence)
try container.encode(role, forKey: .role)
try container.encode(roomKey, forKey: .roomKey)
try container.encode(searchTerm, forKey: .searchTerm)
try container.encode(isAccepted, forKey: .isAccepted)
try container.encode(isDeclined, forKey: .isDeclined)
try container.encode(isBlocked, forKey: .isBlocked)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(updatedAt, forKey: .updatedAt)
}
} |
Hi @peaugust, thanks for letting us know which fields you had to remove to get things working. That does confirm what I suspected, the nested selection set with |
Describe the bug
When I run my app datastore attempts to sync my models data, but on 2 of my models some fields are returning as "Not Authorized to access member on type ". We are using the same infrastructure to web and iOS clients, and just on iOS I'm having this authentication issue when accessing models.
Here's how I configure my Amplify:
Steps To Reproduce
Expected behavior
Be able to sync DataStore without errors
Amplify Framework Version
2.15.2
Amplify Categories
DataStore
Dependency manager
Swift PM
Swift version
5.8.1
CLI version
12.1.1
Xcode version
Xcode 14.3.1 (14E300b)
Relevant log output
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
iOS 16.6
Device
iPhone 13
Specific to simulators
No
Additional context
Here's the models involved in the bug
The text was updated successfully, but these errors were encountered: