-
Notifications
You must be signed in to change notification settings - Fork 0
fix: user issue #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,4 +18,44 @@ public struct User: Codable, Identifiable, Sendable, Equatable { | |||||
| self.email = email | ||||||
| self.image = image | ||||||
| } | ||||||
|
|
||||||
| enum CodingKeys: String, CodingKey { | ||||||
| case id | ||||||
| case sub | ||||||
| case name | ||||||
| case email | ||||||
| case image | ||||||
| case picture | ||||||
| } | ||||||
|
|
||||||
| public init(from decoder: Decoder) throws { | ||||||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||||||
| // Support both "id" and "sub" (OIDC standard) for user identifier | ||||||
| if let id = try container.decodeIfPresent(String.self, forKey: .id) { | ||||||
| self.id = id | ||||||
| } else if let sub = try container.decodeIfPresent(String.self, forKey: .sub) { | ||||||
| self.id = sub | ||||||
| } else { | ||||||
| throw DecodingError.keyNotFound( | ||||||
| CodingKeys.id, | ||||||
| DecodingError.Context( | ||||||
| codingPath: container.codingPath, | ||||||
| debugDescription: "Neither 'id' nor 'sub' found in user info response" | ||||||
| ) | ||||||
| ) | ||||||
| } | ||||||
| self.name = try container.decodeIfPresent(String.self, forKey: .name) | ||||||
| self.email = try container.decodeIfPresent(String.self, forKey: .email) | ||||||
| // Support both "image" and "picture" (OIDC standard) for profile image | ||||||
| self.image = try container.decodeIfPresent(String.self, forKey: .image) | ||||||
| ?? container.decodeIfPresent(String.self, forKey: .picture) | ||||||
|
||||||
| ?? container.decodeIfPresent(String.self, forKey: .picture) | |
| ?? try container.decodeIfPresent(String.self, forKey: .picture) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New decoding behavior supports
subandpicture, but current tests only cover round-trippingidandimage. Add unit tests that decode JSON payloads containing onlysub(noid) and onlypicture(noimage) to ensure this compatibility stays working.