-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: user info from dict to struct type #28
base: main
Are you sure you want to change the base?
Conversation
func dictionaryToJsonData(_ dictionary: [String: Any]) -> Data? { | ||
return try? JSONSerialization.data(withJSONObject: dictionary, options: []) | ||
} |
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.
func dictionaryToJsonData(_ dictionary: [String: Any]) -> Data? { | |
return try? JSONSerialization.data(withJSONObject: dictionary, options: []) | |
} | |
func dictionaryToJsonData(_ dictionary: [String: Any]) -> Data { | |
return try JSONSerialization.data(withJSONObject: dictionary, options: []) | |
} |
return try? JSONSerialization.data(withJSONObject: dictionary, options: []) | ||
} | ||
|
||
func convertUserDataType(dictionary: [String: Any]) throws -> UserInfo? { |
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.
This should not return an optional:
func convertUserDataType(dictionary: [String: Any]) throws -> UserInfo
|
||
func convertUserDataType(dictionary: [String: Any]) throws -> UserInfo? { | ||
if let jsonData = dictionaryToJsonData(dictionary) { | ||
do { |
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.
This do {} catch {} can be removed.
i.e
let decoder = JSONDecoder()
let userInfo = try decoder.decode(UserInfo.self, from: jsonData)
return userInfo
throw "Invalid UserInfo Data structure"; | ||
} | ||
} else { | ||
throw "Invalid UserInfo Data structure"; |
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.
Needs to be of the form:
throw SomeError.SomeCase("Invalid UserInfo Data structure")
Even better is it doesn't accept a message, then it fits nicely in the error handling:
throw UserInfoError.InvalidData
guard let userInfo = self.userInfo else { | ||
throw ("user is not logged in.") | ||
public func getUserInfo() throws -> UserInfo { | ||
do { |
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.
The do {} catch {} can be removed here.
@@ -176,3 +176,94 @@ public struct enableMFARecoveryFactor { | |||
self.additionalMetadata = additionalMetadata | |||
} | |||
} | |||
|
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.
Many of the structs declared here will be in the next version of customauth.
I'd suggest we wait with this PR for that and then update the dependency instead and use it from there.
No description provided.