I'm working on a native iOS app using the MobileSDK. My app defers the login, that is, it does not occur right at the beginning of the app.

From the home screen, users can tap either an "Employee" or "Admin" button to trigger the login process. Post-login, the app segues to different controllers depending on whether the user had tapped "Employee" or "Admin".

When a non-admin employee taps "Admin" and logs in, the SDK's login procedure would obviously succeed. But I need some way to be able to tell, post-login, that this user is not an admin. How would I do this?


No other solution was apparent so I'm using this workaround:

I created a custom field in User called MyApp_UserType, which is a picklist with the values Admin, Employee, and None.

When login succeeds, the completion callback runs a request for the query below

let userId = SFAuthenticationManager.sharedManager().idCoordinator.idData.userId
let isAdminRequest = SFRestAPI.sharedInstance().requestForQuery("select MyApp_UserType__c from User where Id = '\(userId)'")

The success callback for this request checks the user type. If it is Employee or None, a message is displayed and the app returns to the home screen.

It's a bit of an ugly solution since MyApp_UserType isn't tied to the actual user profile and causes needless overhead when creating new users, but it works for now.

  • Why not instead just use the real user profile? You can check there if it is an admin user. – Jonathan Hersh Jul 17 '15 at 17:46
  • @JonathanHersh How do you check that from the REST API? The UserType field just gives the type of license, which isn't of any help. – Aakash Jain Jul 18 '15 at 9:57
  • Look at the user's profileId and return yes for sysadmins. – Jonathan Hersh Jul 18 '15 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.