Skip to content

fix(auth): mark identities last_sign_in_at field as optional #483

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

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading