2

I have created a community and created an Auth. Provider for google and linkedIn. This SSO are working correctly.

My problem is when I login using gmail a new user is created which is linked to gmail. While when I login using linked In with a new user is created.

But I don't want to create a new user if first name, last name and email are common or same. How will I do this?

For e.g. My one user is linked with gmail which has First Name = Swapnil Last Name = Kale Email = test@gmail.com

Now If I try to signup with Linked In with information as above First Name = Swapnil Last Name = Kale Email = test@gmail.com

Two duplicate records are created.

I want to avoid duplicate user creation. How will I achieve this.

What I was thinking is if more same user exist then he will be redirected to vf page to show user with same info. If user already exists then he will select his user and get logged in. Can I redirect to a VF page showing all duplicate users while authenticating?

  • what is the username for both users? username is unique try with this – Ratan Paul Aug 2 '16 at 10:12
  • What do you expect should happen instead? – Nick Cook Aug 2 '16 at 10:15
  • Can you please post the contents of your Registration Handler class? You could query the User object using the firstname and lastname and find existing user and return. For example: user = [select Id from User where FirstName = :data.firstName AND Lastname=:data.lastName limit 1]; return user; – joe Aug 2 '16 at 10:32
0

If you have a Registration Handler class, you could use code similar to below to identify existing user and return.

 global class GoogleAuthRegHandler implements Auth.RegistrationHandler{

    global User createUser(Id portalId, Auth.UserData data){

        User user;

        //Gets user data based on gmail address
        user = [select Id from User where Firstname = :data.firstName AND LastName = :data.lastName limit 1];

        //more code to handle scenario where user doesn't exist already goes here
        return user;

    }
// Other handler methods go here

    }

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.