Skip to content

Commit

Permalink
fix(auth): mark identities last_sign_in_at field as optional (#483)
Browse files Browse the repository at this point in the history
`lastSignInAt`, `updatedAt`, and `createdAt` fields from `UserIdentity` are now optional fields.
  • Loading branch information
grdsdev authored Jul 30, 2024
1 parent d2ec7d3 commit c93cf90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Sources/Auth/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,19 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
public var userId: UUID
public var identityData: [String: AnyJSON]?
public var provider: String
public var createdAt: Date
public var lastSignInAt: Date
public var updatedAt: Date
public var createdAt: Date?
public var lastSignInAt: Date?
public var updatedAt: Date?

public init(
id: String,
identityId: UUID,
userId: UUID,
identityData: [String: AnyJSON],
provider: String,
createdAt: Date,
lastSignInAt: Date,
updatedAt: Date
createdAt: Date?,
lastSignInAt: Date?,
updatedAt: Date?
) {
self.id = id
self.identityId = identityId
Expand Down Expand Up @@ -267,9 +267,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
userId = try container.decode(UUID.self, forKey: .userId)
identityData = try container.decodeIfPresent([String: AnyJSON].self, forKey: .identityData)
provider = try container.decode(String.self, forKey: .provider)
createdAt = try container.decode(Date.self, forKey: .createdAt)
lastSignInAt = try container.decode(Date.self, forKey: .lastSignInAt)
updatedAt = try container.decode(Date.self, forKey: .updatedAt)
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
lastSignInAt = try container.decodeIfPresent(Date.self, forKey: .lastSignInAt)
updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt)
}

public func encode(to encoder: any Encoder) throws {
Expand All @@ -280,9 +280,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
try container.encode(userId, forKey: .userId)
try container.encodeIfPresent(identityData, forKey: .identityData)
try container.encode(provider, forKey: .provider)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(lastSignInAt, forKey: .lastSignInAt)
try container.encode(updatedAt, forKey: .updatedAt)
try container.encodeIfPresent(createdAt, forKey: .createdAt)
try container.encodeIfPresent(lastSignInAt, forKey: .lastSignInAt)
try container.encodeIfPresent(updatedAt, forKey: .updatedAt)
}
}

Expand Down
11 changes: 11 additions & 0 deletions Tests/AuthTests/Resources/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
"last_sign_in_at": "2022-04-09T11:23:45Z",
"created_at": "2022-04-09T11:23:45.899924Z",
"updated_at": "2022-04-09T11:23:45.899926Z"
},
{
"id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
"user_id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
"identity_id": "6c69f399-be1b-467a-9c53-d3753abdd2df",
"identity_data": {
"sub": "6c69f399-be1b-467a-9c53-d3753abdd2df"
},
"provider": "github",
"created_at": "2022-04-09T11:23:45.899924Z",
"updated_at": "2022-04-09T11:23:45.899926Z"
}
],
"created_at": "2022-04-09T11:23:45.874827Z",
Expand Down

0 comments on commit c93cf90

Please sign in to comment.