Strange formatted object returned by Auth0

I’m trying to get data out of an object which I have not seen yet in swift. The type of the object is Any.

    func getMetaData(_ callback: @escaping (Error?) -> ()) {
        guard let accessToken = self.credentials?.accessToken
            else { return callback(CredentialsManagerError.noCredentials) }
        Auth0
            .users(token: accessToken)
            .get(profile!.sub, fields: ["user_metadata"], include: true)
            .start { (result) in
                switch result {
                case .success(let user):
                    print(user)
                    self.metadata = user
                    callback(nil)
                case .failure(let error):
                    callback(error)
                }
        }
    }

The object came to be as a dictionary [String:Any] with any being (print(user)):

["user_metadata": {
    fname = abc;
    lname = xyz;
}]

I got user_metadata out and got this:

{
    fname = abc;
    lname = xyz;
}

This is eventually what I want to achieve:

UserMetaData(fname: "abc", lname: "xyz") 

It’s not quite JSON and I have no clue what to do with it

1 Like

I am not familiar with data type in the context of auth0. Maybe it was setup that way, and is just a string in the metadata?

I fixed it by casting the inner object as another dictionary: self.metadata = (meta["user_metadata"] as! ManagementObject)

2 Likes

Glad to hear you got it figured out!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.