# User creating through google auth

**URL:** <https://community.auth0.com/t/user-creating-through-google-auth/110595>\
**Category:** Get Help\
**Tags:** support-center-self, support-center\
**Created:** [July 5, 2023, 11:48am UTC](https://community.auth0.com/t/user-creating-through-google-auth/110595 "2023-07-05T11:48:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasanthi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prasanthi/32/48572_2.png) [@prasanthi](https://community.auth0.com/u/prasanthi)\
**Post date:** [July 5, 2023, 11:48am UTC](https://community.auth0.com/t/user-creating-through-google-auth/110595/1 "2023-07-05T11:48:27Z")

</div>

I am using google auth2 for social connection and if any user not in auth0 database try to login it is creating new user without user role… So, finally I need to create a user who received invitation that’s it.

how can I do this? and also I am using just free version of auth0

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [July 31, 2023, 7:53pm UTC](https://community.auth0.com/t/user-creating-through-google-auth/110595/3 "2023-07-31T19:53:05Z")

</div>

Hi @prasanthi

Welcome to the Auth0 Community!

From what I understand, you would like to assign a newly signed user via google social connection to the specific role.

One way to achieve this is to use the Action with Post-Login trigger.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count !== 1) {
    return;
  }

  const namespace = "https://my-app.example.com";

  const ManagementClient = require("auth0").ManagementClient;

  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientId,
    clientSecret: event.secrets.clientSecret,
    scope: "read:roles create:roles update:roles",
  });

  const defaultRole = { id :'YOUR_DEFAULT_ROLE_ID_HERE'};

  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    await management.roles.assignUsers(defaultRole, data);
  }

```

With this Action, each new user will be assigned to the `defaultRole` which you I assume already created in the Auth0 Dashboard.

In case you would like to select only google social connection user you need to extend if to the:

```auto
if (event.authorization && event.connection.name==="google-oauth2") event.

```

I hope it will help you  
Thanks and have a great day!

Dawid

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 14, 2023, 7:53pm UTC](https://community.auth0.com/t/user-creating-through-google-auth/110595/4 "2023-08-14T19:53:39Z")

</div>

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