# Is there a way to add a Social Login user to a role or org before they sign in the first time?

**URL:** <https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965>\
**Category:** Get Help\
**Tags:** social-provider, login\
**Created:** [June 10, 2022, 8:34pm UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965 "2022-06-10T20:34:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [June 10, 2022, 8:34pm UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965/1 "2022-06-10T20:34:09Z")

</div>

Currently we have to have users login with their Google creds before we can add their roles and orgs. Is there a way to anticipate that they will be signing in and add the roles to a placeholder ahead of time? It seems tough to have to have them sign in get a unauthorized response then wait while I run the commands.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 10, 2022, 10:46pm UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965/3 "2022-06-10T22:46:56Z")

</div>

Hi @jgleason,

Thanks for reaching out to the Auth0 Community!

I understand that you are trying to add Roles and Organization to a user before they attempt to log in the first time.

In this situation, I recommend leveraging the Post-Login Action script to check for the user’s `login_count` and determine if it’s their first time logging in and adding the roles and Organization to their user profile.  
See an example of adding members to an Organization below:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const ManagementClient = require('auth0').ManagementClient;
  
  if(event.stats.logins_count === 1){
    const management = new ManagementClient({
        domain: event.secrets.domain,
        clientId: event.secrets.client_id,
        clientSecret: event.secrets.client_secret,
    });
    var params = { id :'YOUR_ORG_ID'};
    var data = { members: [event.user.user_id] }
    management.organizations.addMembers(params, data, function (err) {
        if (err) {
            // Handle error.
        }
    });
  }
};

```

Please see [this](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947) FAQ to learn more about using the Management API in Actions.

Please let me know if you help with this.

Thank you!

---

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [June 14, 2022, 4:35pm UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965/4 "2022-06-14T16:35:44Z")

</div>

The problem here is I would need to know what org to add the user to in your example this is hard-coded. I would assume I would need to store this somewhere and deleted once added successfully?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 15, 2022, 5:29pm UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965/5 "2022-06-15T17:29:53Z")

</div>

Hi @jgleason,

Thank you for your response.

> [@jgleason](#):
>
> The problem here is I would need to know what org to add the user to in your example this is hard-coded. I would assume I would need to store this somewhere and deleted once added successfully?

Yes, that is correct. You will need to know what Organization to add to the user. Moreover, instead of hardcoding the `org_id`, I recommend storing the `org_id` as an [Action secret](https://auth0.com/docs/customize/actions/write-your-first-action#add-a-secret), which is suitable for storing sensitive information.

This way, you can add the user to the Organization and will not need to delete the Organization ID after adding successfully.

I hope this helps!

Please let me know if you have any additional questions.

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 11:35am UTC](https://community.auth0.com/t/is-there-a-way-to-add-a-social-login-user-to-a-role-or-org-before-they-sign-in-the-first-time/84965/6 "2022-12-22T11:35:05Z")

</div>


