# Get twitter handle from from SPA

**URL:** <https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [March 21, 2023, 2:01pm UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998 "2023-03-21T14:01:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukesamkharadze](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukesamkharadze/32/45250_2.png) [@lukesamkharadze](https://community.auth0.com/u/lukesamkharadze)\
**Post date:** [March 21, 2023, 2:01pm UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998/1 "2023-03-21T14:01:59Z")

</div>

I’m using `auth0-react` package and use `useAuth0` hook

I want to be able to get user handle but user object doesnt contain that, is there any way to get twitter handle?

```auto
const { isLoading, error, user, loginWithPopup } = useAuth0();

console.log(user)

```

 ![Screenshot 2023-03-21 at 9.58.46 AM](https://global.discourse-cdn.com/auth0/original/3X/e/3/e3467b8d535a73bed1d761e12bdad641ccbb7f19.png)

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 21, 2023, 5:40pm UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998/3 "2023-03-21T17:40:34Z")

</div>

Hey @lukesamkharadze !

You should be able to get the Twitter handle in the user object by adding the `screen_name` to the ID token via a [rule](https://auth0.com/docs/customize/rules/create-rules). The following should work:

```auto
function (user, context, callback) {

   // context.accessToken.twitter_handle = user.screen_name;
  	context.idToken.twitter_handle = user.screen_name;
  
  	return callback(null, user, context);

}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![lukesamkharadze](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lukesamkharadze/32/45250_2.png) [@lukesamkharadze](https://community.auth0.com/u/lukesamkharadze)\
**Post date:** [March 29, 2023, 1:25am UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998/4 "2023-03-29T01:25:34Z")

</div>

Did you mean editing `fetch user profile script` found in custom social integration?

I’m using default twitter social integration, is there any way to get default twitter script and modify it?

I don’t want to write everything from scratch

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 29, 2023, 6:20pm UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998/5 "2023-03-29T18:20:50Z")

</div>

Hey @lukesamkharadze!

> [@lukesamkharadze](#):
>
> Did you mean editing `fetch user profile script` found in custom social integration?

No, the code I shared should be added as a rule. This will add the twitter handle (`user.screen_name`) to the `idToken` which is then available in `useAuth0()`. For example, from [Profile.js](https://github.com/auth0-samples/auth0-react-samples/blob/master/Sample-01/src/views/Profile.js) of the `auth0-react` sample:

```auto
export const ProfileComponent = () => {
  const { user } = useAuth0();

  return (
    <Container className="mb-5">
      <Row className="align-items-center profile-header mb-5 text-center text-md-left">
        <Col md={2}>
          <img
            src={user.picture}
            alt="Profile"
            className="rounded-circle img-fluid profile-picture mb-3 mb-md-0"
          />
        </Col>
        <Col md>
          <h2>{user.twitter_name}</h2>
          <p className="lead text-muted">{user.email}</p>
        </Col>
      </Row>
      <Row>
        <Highlight>{JSON.stringify(user, null, 2)}</Highlight>
      </Row>
    </Container>
  );
};

```

Here’s the exact rule I’m using:

```auto
function (user, context, callback) {

    context.accessToken.twitter_name = user.screen_name;
  	context.idToken.twitter_name = user.screen_name;
  
  	return callback(null, user, context);

}

```

And the rendered profile view in the React sample app:

 ![Screenshot 2023-03-29 at 11.20.23 AM](https://global.discourse-cdn.com/auth0/original/3X/8/3/83c60ec2d887de719f997b4e1b45f49be49accb4.jpeg)

Hope this helps!

---

<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:** [April 12, 2023, 6:21pm UTC](https://community.auth0.com/t/get-twitter-handle-from-from-spa/102998/6 "2023-04-12T18:21:10Z")

</div>

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