Skip to content

Commit c93cf90

Browse files
authored
fix(auth): mark identities last_sign_in_at field as optional (#483)
`lastSignInAt`, `updatedAt`, and `createdAt` fields from `UserIdentity` are now optional fields.
1 parent d2ec7d3 commit c93cf90

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

Sources/Auth/Types.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,19 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
223223
public var userId: UUID
224224
public var identityData: [String: AnyJSON]?
225225
public var provider: String
226-
public var createdAt: Date
227-
public var lastSignInAt: Date
228-
public var updatedAt: Date
226+
public var createdAt: Date?
227+
public var lastSignInAt: Date?
228+
public var updatedAt: Date?
229229

230230
public init(
231231
id: String,
232232
identityId: UUID,
233233
userId: UUID,
234234
identityData: [String: AnyJSON],
235235
provider: String,
236-
createdAt: Date,
237-
lastSignInAt: Date,
238-
updatedAt: Date
236+
createdAt: Date?,
237+
lastSignInAt: Date?,
238+
updatedAt: Date?
239239
) {
240240
self.id = id
241241
self.identityId = identityId
@@ -267,9 +267,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
267267
userId = try container.decode(UUID.self, forKey: .userId)
268268
identityData = try container.decodeIfPresent([String: AnyJSON].self, forKey: .identityData)
269269
provider = try container.decode(String.self, forKey: .provider)
270-
createdAt = try container.decode(Date.self, forKey: .createdAt)
271-
lastSignInAt = try container.decode(Date.self, forKey: .lastSignInAt)
272-
updatedAt = try container.decode(Date.self, forKey: .updatedAt)
270+
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
271+
lastSignInAt = try container.decodeIfPresent(Date.self, forKey: .lastSignInAt)
272+
updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt)
273273
}
274274

275275
public func encode(to encoder: any Encoder) throws {
@@ -280,9 +280,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
280280
try container.encode(userId, forKey: .userId)
281281
try container.encodeIfPresent(identityData, forKey: .identityData)
282282
try container.encode(provider, forKey: .provider)
283-
try container.encode(createdAt, forKey: .createdAt)
284-
try container.encode(lastSignInAt, forKey: .lastSignInAt)
285-
try container.encode(updatedAt, forKey: .updatedAt)
283+
try container.encodeIfPresent(createdAt, forKey: .createdAt)
284+
try container.encodeIfPresent(lastSignInAt, forKey: .lastSignInAt)
285+
try container.encodeIfPresent(updatedAt, forKey: .updatedAt)
286286
}
287287
}
288288

Tests/AuthTests/Resources/user.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
"last_sign_in_at": "2022-04-09T11:23:45Z",
2727
"created_at": "2022-04-09T11:23:45.899924Z",
2828
"updated_at": "2022-04-09T11:23:45.899926Z"
29+
},
30+
{
31+
"id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
32+
"user_id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
33+
"identity_id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
34+
"identity_data": {
35+
"sub": "6c69f399-be1b-467a-9c53-d3753abdd2df"
36+
},
37+
"provider": "github",
38+
"created_at": "2022-04-09T11:23:45.899924Z",
39+
"updated_at": "2022-04-09T11:23:45.899926Z"
2940
}
3041
],
3142
"created_at": "2022-04-09T11:23:45.874827Z",

0 commit comments

Comments
 (0)