Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

guru-web3
Copy link
Contributor

No description provided.

Comment on lines +84 to +86
func dictionaryToJsonData(_ dictionary: [String: Any]) -> Data? {
return try? JSONSerialization.data(withJSONObject: dictionary, options: [])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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? {
Copy link
Contributor

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 {
Copy link
Contributor

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";
Copy link
Contributor

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 {
Copy link
Contributor

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
}
}

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants