Access user_metadata from profile on iOS?

On iOS, while using Lock, we’re adding a custom textfield to let user type in their first name.
I see this is then stored in user_metadata.

It seems like I can’t get this firstName from the profile though:

Lock
        .classic()
        .withStyle {
            $0.hideTitle = true
    }
    .withOptions {
        $0.oidcConformant = true
        $0.scope = "openid profile email"
        $0.audience = "xxxxxxxxxxx"
        $0.initialScreen = .signup
        $0.allow = [.Signup]
        $0.customSignupFields = [
            CustomTextField(name: "firstName", placeholder: "Your first name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle))
        ]
        $0.termsOfService = "https://mycompany.com/terms"
        $0.privacyPolicy = "https://mycompany.com/privacy"
    }
    .onAuth { credentials in
        
        if self.credentialsManager.store(credentials: credentials) {
            
            guard let accessToken = credentials.accessToken else { return }
            
            self.testApiCallWithToken(token: accessToken, completionHandler: { (response) in
                // do smth
            })
            
            Auth0
                .authentication()
                .userInfo(withAccessToken: accessToken)
                .start { result in
                    print(result)
                    switch result {
                    case .success(let profile):
                        // How do I get user firstName now? profile.user_metadata isnt accessible
                       
                    case .failure(let error):
                        print(error)
                    }
            }
        }
        
    }
    .present(from: self)

Am I missing something?

Thank you in advance!

Found an answer to my question:

CustomTextField(name: "given_name", placeholder: "Your first name", storage: .rootAttribute, icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .givenName)

I had to use parameters storage: rootAttribute and contentType: .givenName
For the custom textfield value to be added to the profile.

1 Like

Voila! Thanks for sharing that solution with the rest of community developers!

1 Like

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