How to determine if a user is social ,

I was using this to determine if it is social , Identity class is not found

  let userInfo = try await Auth0
                .users(token: accessToken)
                .get(userSub, fields: ["user_metadata"])
                .start()
            
            let userMetadata = userInfo["user_metadata"] as? [String: String?] ?? ["": ""]
            
            
            let identityValues = userInfo["identities"] as? [[String: Any]] ?? []
            let isSocial = identityValues.compactMap { Identity(json: $0) }.contains{ $0.social }

Hey there @huthefa.alfararjeh welcome to the community!

You might want to just add the “identities” array as a custom claim to the ID token and go about getting it that way - Here’s an action that does this for example:

exports.onExecutePostLogin = async (event, api) => {

  if (event.authorization) {
    api.idToken.setCustomClaim('identities', event.user.identities)
  }
}

Hope this helps!

this is not my question, sorry!

Hey there @huthefa.alfararjeh thanks for getting back to me - Sorry for not being more clear in my previous response. I was suggesting a method for adding the identities array directly to the user’s ID token.

If I’m understanding the code you shared correctly, you’re using the Auth0.Swift SDK’s management client to get a user. Currently it looks like you’re specifically requesting the user_metadata attribute and only that. Have you tried adding identities to fields? I believe the way the method works is that if you include specific attributes in the request, any others not specified are excluded. Perhaps try the following:

let userInfo = try await Auth0
                .users(token: accessToken)
                //only line changed to include "identities"
                .get(userSub, fields: ["user_metadata", "identities"]) 
                .start()
            
            let userMetadata = userInfo["user_metadata"] as? [String: String?] ?? ["": ""]
            
            
            let identityValues = userInfo["identities"] as? [[String: Any]] ?? []
            let isSocial = identityValues.compactMap { Identity(json: $0) }.contains{ $0.social }

Let us know!

thank you very much , “Cannot find ‘Identity’ in scope”

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